[英]jQuery/javascript and setInterval not working correctly within mouseenter
Ok so basically I'm implementing a simple horizontal scroller. 好吧基本上我正在实现一个简单的水平滚动条。 The function gets fired when I move the mouse into the correct div but only once and doesn't keep looping after the interval time.
当我将鼠标移动到正确的div但只有一次并且在间隔时间之后不保持循环时,该函数被触发。 Any help appreciated:
任何帮助赞赏:
$(document).ready(function() {
$('#toparrow').mouseenter(function(e) {
var func = scrollroller(1);
setInterval(func,1);
}).mouseleave(function() {
});
function scrollroller(velocity) {
$('#roller').animate({left:'+='+velocity},1);
}
});
var func = function(){ scrollroller(1); };
The problem is with this line: 问题出在这一行:
var func = scrollroller(1);
This isn't assigning the scrollroller
function to func
, it is invoking scrollroller()
with a parameter of '1' and storing the result in func
. 这不是将
scrollroller
函数赋值给func
,而是调用参数为'1'的scrollroller()
并将结果存储在func
。 You probably want to do something like: 你可能想做类似的事情:
setInterval("scrollroller(1);",1); //alternately: setInterval(scrollroller,1,1);
Note that the alternate syntax may have issues in IE . 请注意,替代语法可能在IE中存在问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.