Jump to content

Image Lag


BrandonE97

Recommended Posts

Between the time someone mouses over a rollover image and the downloading of the image there is nothing under the mouse (an image) and I was wondering what I could do to fix that so an image is always shown (even if its the first one, not the rollover image) so everything looks better in the image rollover. No time where there is no image showing. Thanks!

 

a.navlink, a:visited.navlink, a:link.navlink {
display:block;
width:100px;
height:20px;
padding-top:2px;
font-size:12px;
text-decoration:none;
color:#000000;
background-image:url(/theme/navlinka.gif);
background-repeat:no-repeat;
text-align:center;
}
a:hover.navlink {
display:block;
width:100px;
height:20px;
padding-top:2px;
font-size:12px;
font-weight:bold;
text-decoration:none;
color:#000000;
background-image:url(/theme/navlinkb.gif);
background-repeat:no-repeat;
text-align:center;
}

Link to comment
https://forums.phpfreaks.com/topic/49307-image-lag/
Share on other sites

That's because the rollover images are not loaded with the page content. A javascript image preloader should resolve the problem ;D 

 

function preloadImages(urls) {
  var img = new Array();
  for (var i=0; i<urls.length; i++) {
    img[img.length] = new Image();
    img[img.length - 1].src = urls[i];
  }
}

window.onload = function() {
// rollover images
  var img = new Array("active.gif",
                              "inactive.gif",
                              "other.gif");
  preloadImages(img);
}

 

 

Later.

Link to comment
https://forums.phpfreaks.com/topic/49307-image-lag/#findComment-241749
Share on other sites

Here is how I normally do my css rollover images. I start by creating a new image and then stacking my other two images on top of each other. Like this

demo.gif

So on the top you will want the first image that will be shown and then on the bottom you will put the hover image. Here is the css for something like that.

.rollOver  {	
height: 40px;
width: 100px;
}

.rollOver a {
background: #FFFFFF url(demo.gif);
display: block;
float: left;
line-height: 40px;
height: 40px;
width:100px;
text-decoration: none;
}
.rollOver a:hover {background-position: left bottom; }

 

The html

<span class="rollOver"><a href="#">Whatever</a></span>

 

You will have to define the height and width of your rollover image. Now when the image is moused over the background image position will change. This enables us to get rid of that lag and does not require any javascript.  Here is  a demo

Link to comment
https://forums.phpfreaks.com/topic/49307-image-lag/#findComment-241963
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.