当用户连续按下按钮或按住按钮时,我想连续调用一个功能。当用户按下并且当用户释放按钮时,我已经尝试了两次功能调用。我试过这个:
zoomIn.on("mousedown", function (e) {
setTimeout(function() {
ImageViewer.zoomImage(30, true);
}, 300);
});
这不能正常工作。我有办法做到这一点吗?
答案 0 :(得分:2)
你可以试试这样的:
var interval,
time = 100;
var zoom = function() {
//your zooming code:
ImageViewer.zoomImage(30, true);
};
var startZoom = function() {
interval = setInterval( zoom, time );
};
var stopZoom = function() {
clearInterval( interval );
};
zoomIn.on("mousedown", startZoom);
zoomIn.on("mouseup", stopZoom);