gpt4 book ai didi

javascript - SetInterval 只调用一次,不知道为什么?

转载 作者:行者123 更新时间:2023-11-30 08:54:40 25 4
gpt4 key购买 nike

<分区>

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');
}

我的问题是设置间隔函数只被调用一次,而不是像我试图让它做的那样每秒调用一次。我做错了什么?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com