Take Some Code
Showing posts with label how to. Show all posts
Showing posts with label how to. Show all posts

Monday, March 12, 2012

Preloading Images JavaScript

Hello folks...
Want to know how to load an image before the user sees it?
Then read on.

We all hate moments like these online:
Not sure if slow Internet or a pixelated image.

Here is the free code bit today:


<div class="hidden">
        <script type="text/javascript">
<!--//--><![CDATA[//><!--
        var images = new Array()
            function preload() {
                for (i = 0; i < preload.arguments.length; i++) {
                    images[i] = new Image()
                    images[i].src = preload.arguments[i]
                }
            }
            preload(
"http://www.navsounds.com/blogimages/button200x200of.gif",
)
            //--><!]]>
        </script>
    </div>


The code above is all about preloading your images. For those who don't know what that means or what it can do for you and your blog. Preloading images is exactly what it sounds like. When you write the code above into an HTML page or blog layout the browser looks at it and finds this spot:

            preload(
"http://www.navsounds.com/blogimages/button200x200of.gif"
)
Then it loads that image into a hidden area on the page so that the user doesn't see it until they are supposed to.



























Drives you nuts doesn't it?



We all hate waiting for site data to download or for content to change on a page. Preloading images can help alleviate that problem by downloading the images into the users cache before they are needed.
I use this exact script to get my fancy blog button loaded so that when the user mouses over the button it can display the fancy, but large GIF file immediately.
The blog button that you see without interaction is a very small file, but to have the animation that I have when you mouse over my button it required having a 1.1MB GIF picture.
If I hadn't preloaded the GIF the user would have to wait anywhere from a couple of seconds to a minute depending on the their connection speed just to see my cool animation. (As you may have had to with this example.)
The preloading of my blog button saves the user from waiting so that when they hover over my button it is ready to play and works immediately.


You can utilize to this code on your blog or site to produce a similar result. If you have multiple pages on your blog for example and one of them contains a lot of pictures you could use this script to preload those images so that the user doesn't have to wait to see them when they navigate to your "pictures" page. Or if you are utilizing mouse over images it can help the image to be ready the instant the user mouses over.


Simply replace the contents of the quotes with the source location of the image you want to preload:

            preload(
"Where your image is"
)
If you have multiple images that you want to load do this:

  preload(
"Where your image is" ,
                                "Where your second image is",
                                "Etc."
)
Then take all of the code and put it inside an HTML/JavaScript widget.

<div class="hidden">
        <script type="text/javascript">
<!--//--><![CDATA[//><!--
        var images = new Array()
            function preload() {
                for (i = 0; i < preload.arguments.length; i++) {
                    images[i] = new Image()
                    images[i].src = preload.arguments[i]
                }
            }
             preload(


"WHERE YOUR IMAGE IS" ,
                                "WHERE YOUR 2ND IMAGE IS",
                                "ETC."


)
            //--><!]]>
        </script>
    </div>



Enjoy!
As always post any comments or questions...



Saturday, March 3, 2012

HTML Basics


Introductions...
Hello my name is Mike and I am the wonderfully fantastic husband of Alyx from Everyday is a New Adventure.

I have created this blog as a means of sharing HTML, javaScript, CSS, and other types of code.
Followers will receive daily ideas and code tips to improve their own blog and learn some web design in the process.

Without further ado... I will now introduce HTML.

HTML is a computer programming language designed for the world wide web.
It is also an acronym that stands for Hyper-text Markup Language.


Those who remember the beginnings of the internet will remember a time when dial-up abounded with it's silly tones and websites were plain and boring.Most websites consisted of just text and maybe a few pictures and standard links.


The term mark up refers to adding marks or annotations to a document so that they are not displayed, but rather show the browser how to display something.

HTML consists of elements which each tell the browser to do something different.
You use many of them already I'm sure while blogging such as the break element <br /> or the image element <img... />. A web browser's job such as Google Chrome, Firefox, IE, or Safari is to read a webpage file like "index.html" and then display the page as it says to in the file.

A webpage can be created in just 9 lines of code:
<html>
<head>
<title>Title of your webpage
</title>
</head>
<body>
Whatever you want to display on the page
</body>
</html>

Now to explain it.
<html> - tells the browser that everything after that line is part of the webpage.
<head> - tells the browser that after this line is where you can put stuff that you don't want to show up in the body.
<title> - creates the title of the webpage and </title> ends the title.
</head> - ends the head section.
<body> - begins the body section where you put all of the pages content including pictures, text, links, and more.
Between the <body> and </body> is content.
</body> - closes the body section
</html> - ends the webpage.

And that's it. To create your own webpage all you would have to do is put these 9 lines of code into a standard text document, and then rename the extension from "textdocument.txt" to "textdocument.html" and now you have created a webpage.

Here is a step by step guide:
1) Create a text document on PC or MAC
2) Edit the document in a text editor such as Notepad (PC) or TextEdit(MAC)
3) Copy the code above by selecting it pressing Ctrl + C or Apple key + C
4) Paste the code in the text document by pressing Ctrl + V or Apple key + V
5) Save the text document and close it
6) Rename the text document from "TextDocument1.txt" to "whateveryouwant.html"
7)Done. Double click on the new file to open it in your default browser.
or
YouTube tutorial made by me... Enjoy the background music because I made that too...


That's all for today... I don't want to bore you with too much code, but for those looking for a freebie webpage built just like the example above Take Some Code here.

Have a good one!
(c) 2012 Take Some Code