Loop until jQuery mouseenter(); occurs and while mousedown
How would you solve that? It should be scrolling while the mousebutton is down and the mouse left the (#List) ...
That's what i开发者_Python百科 have done meanwhile, but i don't know how to check, if the jQuery mouseenter event occured and if the mousebutton is down ...
$('#List').mouseleave(function(){
var api = $(scrollPane).data('jsp');
while ( ??? ){
api.scrollByY(50, false);
}
});
Any suggestions?
Never, ever, put Javascript into a "busy" loop. It will make your browser unresponsive.
Assuming that what you want is possible (I'm not sure it is, since events that start in one element and finish in another are tricky), you'll need to something like:
function doScroll() {
api.scrollByY(50, false);
}
$('#List').mouseleave(function(ev) {
var timer = null;
if (ev.which) { // if a button is pressed
timer = setInterval(doScroll, 200); // regularly call 'doScroll'
$(document).one('mouseup', function() { // and register a one-off mouseup
clearInterval(timer); // which stops the timer
timer = null;
}
}
});
NB: untested, may not work, omissions and errors likely, etc.
Thank you for your quick answer! After studying a lot event and setInterval stuff i know a lot more about this topic ... but still one thing: ev.which
is always "1" wheter i hold down the left mouse button while leaving the "#List" or not ... when i hold down the right or the middle mouse button it changes to 2 and 3 ... same with the event property button it does not make a difference holding the left mouse button or not ...
精彩评论