<分区>
Possible Duplicate:
setInterval only runs once?
在我继续之前,让我说作为一个设计师逻辑来的困难,所以我很感激你能忍受我的无知。
我正在制作一个简单的 slider ,我希望这样当用户用鼠标移动图片时,程序可以记下 mouseup() 之前最后一秒所覆盖的距离,这样我就可以计算图片必须移动多少才能模拟被滑动的效果。
我有这样的基本事件处理程序:
$('.testdiv').mousedown(function(){
pretestFunction();
//mouse is pressed
mousepressed = 1;
//set first X point
prevX = event.pageX;
}).mouseup(function(){
//get stop X point
stopX = event.pageX;
mousepressed = 0;
});
pretestFunction 调用 setInterval,如下所示:
function pretestFunction(){
window.setInterval(testFunction(), 1000);
}
测试函数():
function testFunction(){
console.log('1 second');
}
我的问题是设置间隔函数只被调用一次,而不是像我试图让它做的那样每秒调用一次。我做错了什么?