当鼠标处于保持状态时,如何修改下面的代码以持续滚动对象?点击即可使用此代码。
.on("click.jstree", ".down-arrow", $.proxy(function (e) {
var obj = this.get_element(e.target);
obj["page_num"] += 1;
obj["arrow"] = true;
this.draw_next(obj);
}, this))
我尝试使用mousedown.jstree和setInterval()但它没有用。
.on("mousedown.jstree", ".down-arrow", $.proxy(function (e) {
var interval;
interval = setInterval (function () {
var obj = this.get_element(e.target);
obj["page_num"] += 1;
obj["arrow"] = true;
this.draw_next(obj);
}, 50);
}, this))
.on("mouseup", ".down-arrow", $.proxy(function (e)) {
clearInterval(interval);
}, this))
答案 0 :(得分:0)
设置一个标志,然后使用while()
循环继续做你需要做的事情。然后最终将旗帜设置为假!
// set a flag
var mouseIsDown = false;
// create function to do "stuff" when mouse is down
function mouseDownAction(){
while(mouseIsDown){
// do some code
}
}
// set event listener to set flag to true and fire function
$(some_selector).on('mousedown', function(){
mouseIsDown = true;
mouseDownAction();
});
// change flag to false on mouseup
$(some_selector).on('mouseup',function(){ mouseIsDown = false; });