开发者

jQuery: How to make news ticker stop move when over on it

开发者 https://www.devze.com 2022-12-25 17:13 出处:网络
Does anyone help me to make the news items stop moving when hover on it? http://geschke.name/dev/newsticke开发者_JAVA技巧r/

Does anyone help me to make the news items stop moving when hover on it?

http://geschke.name/dev/newsticke开发者_JAVA技巧r/

Many thanks.


I believe you would do it like this:

$('ul#listticker').hover(pauseTicker, resumeTicker);

function pauseTicker() {
    clearInterval(interval);
}

function resumeTicker() {
    interval = setInterval(newsticker, pause);
}


You can do this by adding this to the same $(document).ready(function(){ });, or move function newsticker() outside the document.ready function, which would be a bit better.

$("#listticker").hover(function() {
  clearInterval(interval);
}, function() {
  interval = setInterval(newsticker, pause);
});

This cancels the interval when hovering, and resumes it when the mouse leaves.

0

精彩评论

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