开发者

jQuery fadeOut() function doesn't ALWAYS work in Chrome, Firefox, IE

开发者 https://www.devze.com 2023-01-03 19:28 出处:网络
Sometimes, the slideshow on my website, which uses fadeOut and fadeIn to cycle through three main images will fadeIn a new photo without fading the old one. This doesn\'t happen every time the page lo

Sometimes, the slideshow on my website, which uses fadeOut and fadeIn to cycle through three main images will fadeIn a new photo without fading the old one. This doesn't happen every time the page loads though. My site is here (the slideshow will take 7 seconds to change): http://codersarepeople.com/v2/

The code I use is this

slideshow = new Array('#slideshow1','#slideshow2','#slideshow3');
var i = Math.floor(Math.random()*3);
$(slideshow[i]).开发者_开发知识库fadeIn(125);
var t = setInterval(function() {
 $(slideshow[i%3]).fadeOut(250,function() {
  $(slideshow[(i+1)%3]).fadeIn(250);
 });
 i++;
},7000);


It turns out, the error only occurs when the random variable i = 0. I just cheated and forced it to either equal 1 or 2. I still don't know why that was happening though.

0

精彩评论

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