0

我写了这段代码,它现在为我制作了一个幻灯片,当鼠标悬停时我需要停止向上滑动

$(document).ready(function () {
$('#ticker_02').mouseover(function() {
  //I NEED THIS CODE
    })

});

function tick2(){
    $('#ticker_02 li:first').slideUp( function () { $(this).appendTo($('#ticker_02')).slideDown(); });
}
setInterval(function(){ tick2 () }, 2000);
4

3 回答 3

1

尝试stop()方法:

$('#ticker_02').mouseover(function() {
  $(this).stop(true);
})
于 2012-05-27T09:07:10.790 回答
0

function tick2(){
  $('#ticker_02 li:first').slideUp(
    function () {
      $(this).appendTo($('#ticker_02')).slideDown();
    }
  );
}

d=setInterval(function(){ tick2 () }, 5000);

function stop1(){
  clearInterval(d);
}
function start1(){
  d=setInterval(function(){ tick2 () }, 5000);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="ticker_02" class="ticker" onmouseover="stop1()" onmouseout="start1()" >
  <li>element1</li>
  <li>element2</li>
</ul>

于 2016-09-30T10:08:25.273 回答
0

尝试这个。

<ul id="ticker_02" class="ticker" onmouseover="stop1()" onmouseout="start1()">

<script>
var d
function tick2(){
    $('#ticker_02 li:first').slideUp( function () {    
        $(this).appendTo($('#ticker_02')).slideDown(); });
}
d=setInterval(function(){ tick2 () }, 2000);


function stop1(){
    clearInterval(d);
}

function start1(){
    setInterval(function(){ tick2 () }, 2000);
}
</script>
于 2016-09-30T10:11:44.837 回答