在我開始讓我說作爲一個設計師的邏輯來難,所以我很感謝你我的無知軸承。
我正在製作一個簡單的滑塊,並且我希望它能夠在用戶使用鼠標移動圖片時,程序可以記錄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);
}
testfunction():
function testFunction(){
console.log('1 second');
}
我的問題是設置的間隔函數只被調用一次,而不是每秒一次,就像我試圖去做的那樣。我究竟做錯了什麼?
你可以做小提琴嗎? – Mooseman