开发者

Annoying Bug in banner cycle

开发者 https://www.devze.com 2023-02-11 17:20 出处:网络
I have created a rotating banner script for a new site I\'m开发者_Python百科 developing View banner here(it rotates every 10 seconds)

I have created a rotating banner script for a new site I'm开发者_Python百科 developing View banner here(it rotates every 10 seconds)

Unfortunately to the transition seems to be a biut buggy, and the image will fade out, show the same image again and then fade in the new one. I think I have made a simple error somewhere, but can't figure out where it is. the code used to cycle the banners is:

In document ready:

if ($('.home').length > 0){
        $('<img width="100%" />').attr('src', '/assets/img/backgrounds/home/hero'+homecount+'.jpg').load(function(){
                $('.hero').append( $(this) );
                $('.hero img').fadeIn('medium').delay(10000).fadeOut('slow', loopImages);
                setHeroHeight();
        });
    }

Outside document ready:

function loopImages(){
    homecount = homecount+1;
    if (homecount > 5){
        homecount = 1;  
    }
    $('.hero img')
        .attr('src', '/assets/img/backgrounds/home/hero'+homecount+'.jpg')
        .load(function(){ $('.hero img').fadeIn('fast')}).delay(10000).fadeOut('slow', loopImages);
}

Any help would be greatly appreciated

Thanks

Dave


I had a very similar problem when i was trying to show a series of quotes in a div, i achieved it by using the folowing code

 $(document).ready(function(){
   function runIt(){
     $('*img*').each(function(i, elem) {
       $("*container*").delay(5000).fadeOut(1000, function() {
         $(this).html($(elem).html());
       }).fadeIn(1000, runIt);
     });
   };
   runIt()
 });

*img*: here you're calling your images

*container*: this is the element where you want your image to appear.

You can see the code in action here: dinwoodie.net

0

精彩评论

暂无评论...
验证码 换一张
取 消