2013-02-20 31 views
0

我有一个报价旋转设置,一次显示两个引号,并在各地之间跳跃时,它应该只是在每个之间平稳旋转。 我无法弄清楚发生了什么问题。看到它在行动这里 - http://jsfiddle.net/RF3xK/1/jQuery报价旋转使用slideUp和slideDown

代码如下,

<div id="quotes"> 
<div class="textItem"> 
    testing the quotes testing the quotes 
</div> 
<div class="textItem"> 
    asdfdsaf sdf sdf sdf sf sd fsdaf sdf sdaf sdfsd f ds f dsf asdfsdafdsaf asdfdsaf sdf sdf sdf sf sd fsdaf sdf sdaf sdfsd f ds f dsf asdfsdafdsaf 
</div> 
<div class="textItem"> 
    and another one 
</div> 

和jQuery的

$(document).ready(function() { 
$('#quotes .textItem').hide(); 
InOut($('#quotes .textItem:first')); 

function InOut(elem) { 
elem.delay().slideUp(800).delay(0).slideDown(0, function() { 
    if (elem.next().length > 0) { 
     InOut($(this).next()); 
    } 
    else { 
     InOut($(this).siblings(':first')); 
    } 
}); 
} 

$('#quotes .textItem').mouseover(function() { 
$(this).stop(true, true); 
}); 
$('#quotes .textItem').mouseout(function() { 
if ($(this).is(":visible") == true) { 
    InOut($(this)); 
} 
}); 
}); 
+0

它似乎按照我的意图工作..究竟是什么问题? – 2013-02-20 00:43:22

+0

什么是'elem.delay()。slideUp(800).delay(0).slideDown(0,'应该这样做?向上滑动800ms,然后立即向下滑动? – Fresheyeball 2013-02-20 01:30:18

回答

1

我看不到的方式与方法来解决它,你写了它,所以这里是一个不同的方法:

http://jsfiddle.net/tFHWf/2/

var InOutInterval; 
$(document).ready(function() { 
    var textItems = $('.textItem'), 
     i = 0, 
     setInOut = function(){   
      clearInterval(InOutInterval); 
      InOutInterval = setInterval(function(){   
       textItems.eq(i%textItems.length).slideUp(); 
       textItems.eq((i+1)%textItems.length).slideDown(); 
       i++ 
      }, 800);   
     }, 
     pauseInOut = function(){ 
      clearInterval(InOutInterval); 
     }; 
    textItems.eq(0).show(); 
    setInOut();  
    $('#quotes').hover(pauseInOut,setInOut); 
}); 
+0

谢谢,效果很好。第一个显示器没有等待800毫秒出现? – user537137 2013-02-20 02:52:22

+0

答案更新。 – Fresheyeball 2013-02-20 05:24:10

+0

真棒,谢谢! – user537137 2013-02-20 06:16:48