Forum Moderators: not2easy

Message Too Old, No Replies

image preloading problems

can't make it work

         

8PDesign

6:34 pm on Nov 2, 2009 (gmt 0)

10+ Year Member



hi, I posted to CSS forum, but I am not even sure this is a CSS problem.

Although I tried every trick, my background images for my main menu are not preloading... hence it flickers on first attempt. This is because the browser request the image... You'll have to Force refresh or clear cache to see it again.

But if you have Firebug net panel open, you will see that the images WERE already loaded... and that your roll over will trigger the request again.

So why can't I get those background images to load?!

Please see the following page:
<snip>

thanks for your help!

[edited by: swa66 at 7:02 pm (utc) on Nov. 2, 2009]
[edit reason] No links, please see ToS and Forum Charter. [/edit]

D_Blackwell

6:45 pm on Nov 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The personal link is going to get chopped, so I cannot use it as a reference for markup suggestions. If the images are truly pre-loaded, they should pop right up. (I saw no issue in rendering, but have a 16MB connection.)

8PDesign

6:54 pm on Nov 2, 2009 (gmt 0)

10+ Year Member



hi,

2-if you force refresh you don't see the flicker? I guess it's your 16MB connection, because I have a 7MB here, and I do see it flicker on multiple computers... and it's a killer on 700k

thanks!

[edited by: swa66 at 7:34 pm (utc) on Nov. 2, 2009]
[edit reason] ToS #24 [webmasterworld.com] [/edit]

8PDesign

7:53 pm on Nov 2, 2009 (gmt 0)

10+ Year Member



ok, this is the cleanest code I could come to to show my problem. Hoping to get help on this. thanks!

I would hope NOT to see the flicker on roll-over. (which happens only the first time). thanks!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>test</title>
<meta name="keywords" content="" />
<meta name="description" content="" />

<style type="text/css">
#nav_portfolio { width:320px; height:138px; background:url(http://www.google.com/logos/clickortreat1.gif) no-repeat; display:block; cursor:pointer;}
#nav_portfolio:hover { width:320px; height:138px; background:url(http://www.google.com/logos/clickortreat2.gif) no-repeat; display:block; cursor:pointer;}
</style>
</head>

<body>
<div id="header">
<div class="navigators">
<div class="suckertreemenu">
<ul id="treemenu1">
<li><a id="nav_portfolio" href="#"></a></li>
</ul>
</div>
</div>
</div>

<script type="text/javascript">
<!--
var myimages = new Array();
function preloading(){
for (x=0; x<preloading.arguments.length; x++){
myimages[x] = new Image();
myimages[x].src = preloading.arguments[x];
}
}
preloading("http://www.google.com/logos/clickortreat2.gif");
// -->
</script>
</body>

</html>

swa66

7:57 pm on Nov 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Describe the "flicker" you see ...

What browser is causing you trouble ?

Try removing all style from the :hover except for what changes (the background-image)

I always use CSS sprites for this: they are always loaded and never flicker.

8PDesign

8:39 pm on Nov 2, 2009 (gmt 0)

10+ Year Member



1-flicker is white between image
http://www.google.com/logos/clickortreat1.gif
white
http://www.google.com/logos/clickortreat2.gif

where I would expect
http://www.google.com/logos/clickortreat1.gif
http://www.google.com/logos/clickortreat2.gif

2-Firefox 354, Safari 4, IE 6, IE7, IE8

In Firebug... you'll see that clickortreat1.gif is called (by the CSS), then clickortreat2.gif is called by the javascript

then when I roll over, clickortreat2.gif is called AGAIN by the hover CSS.

any help?
thanks!

[edited by: swa66 at 1:47 pm (utc) on Nov. 3, 2009]
[edit reason] unlinking [/edit]

StoutFiles

1:07 pm on Nov 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you start using Javascript for design you are rolling the dice. Anyway you could just discard preloading images altogether?

8PDesign

1:29 pm on Nov 3, 2009 (gmt 0)

10+ Year Member



hi Stout, I tried CSS hidden div and off-position images to preload my images. Yet, on hover, the request is made again.

So really, javascript or not, my image does not preload. I can't believe it.

swa66

1:39 pm on Nov 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try changing
#nav_portfolio:hover { width:320px; height:138px; background:url(http://www.google.com/logos/clickortreat2.gif) no-repeat; display:block; cursor:pointer;}

to
#nav_portfolio:hover { background-image:url(http://www.google.com/logos/clickortreat2.gif);}

You really only need that portion anyway.

Notice I'm not using the shorthand background, but the more specific background0image which does not reset all other background values to their default.

If that's not doing it,

Try using CSS sprites:
- glue both your images into one larger image (let's say one above the other)
- only change the position of the background image on the :hover
It's really the better solution anyway.

8PDesign

2:00 pm on Nov 3, 2009 (gmt 0)

10+ Year Member



hi swa66, thanks for your reply, I tried it... no change.
I might look into sprites... but now I don't understand this simple thing.

1-I please the secondary image in the layout so both images show. STILL, when I roll-over the first time, I still get a network access for the hove image. This is incredible. Please look at this, thanks:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>test</title>
<meta name="keywords" content="" />
<meta name="description" content="" />

<style type="text/css">
#nav_portfolio { width:320px; height:138px; background-image:url(http://www.google.com/logos/clickortreat1.gif); background-repeat:no-repeat; display:block;}
#nav_portfolio:hover { background-image:url(http://www.google.com/logos/clickortreat2.gif);}
</style>

</head>

<body>

<a id="nav_portfolio" href="#"></a>
<img src="http://www.google.com/logos/clickortreat2.gif" />

</body>
</html>

8PDesign

2:18 pm on Nov 3, 2009 (gmt 0)

10+ Year Member



As you see in the code above, my hover image (clickortreat2.gif) is ALREADY loaded in the page in an img tag.

I am wondering why my page request the clickortreat2.gif image AGAIN on #nav_portfolio:hover.

It's already downloaded... why request it again?!

thanks!

swa66

2:47 pm on Nov 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Google is serving that image with a request not to cache it in the HTTP header.

8PDesign

2:53 pm on Nov 3, 2009 (gmt 0)

10+ Year Member



ok, so I placed the images on my server and get the same problem.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>test</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<style type="text/css">
#nav_portfolio {background-image:url('http://www.example.com/clickortreat1.gif'); width:320px; height:138px; display:block;}
#nav_portfolio:hover {background-image:url('http://www.example.com/clickortreat2.gif');}
</style>
</head>

<body>
<p>
<a id="nav_portfolio" href="#"></a>
<br/>
<img src="http://www.example.com/clickortreat2.gif" alt="" />
</p>
</body>
</html>

[edited by: swa66 at 2:56 pm (utc) on Nov. 3, 2009]
[edit reason] No personal URLs, please see ToS and Forum Charter. [/edit]