循环直到 jQuery mouseenter();发生并且当鼠标按下时

发布于 2024-10-24 22:59:55 字数 295 浏览 8 评论 0原文

你会如何解决这个问题? 它应该在鼠标按钮按下并且鼠标离开 (#List) 时滚动...

这就是我同时所做的,但我不知道如何检查 jQuery mouseenter 事件是否发生以及鼠标按钮是否按下...

$('#List').mouseleave(function(){
    var api = $(scrollPane).data('jsp');
    while ( ??? ){
       api.scrollByY(50, false);
    }
});

有什么建议吗?

How would you solve that?
It should be scrolling while the mousebutton is down and the mouse left the (#List) ...

That's what i 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

横笛休吹塞上声 2024-10-31 22:59:55

永远、永远不要将 Javascript 置于“繁忙”循环中。它会使您的浏览器无响应。

假设你想要的东西是可能的(我不确定它是不是,因为在一个元素中开始并在另一个元素中结束的事件很棘手),你需要类似的东西:

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:未经测试,可能不起作用,遗漏和错误可能等等

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.

荒路情人 2024-10-31 22:59:55

感谢您的快速答复!在研究了很多 event 和 setInterval 的东西之后,我对这个主题有了更多的了解...但仍然有一件事:无论我按住什么,ev.which 总是“1”是否离开“#List”时按下鼠标左键...当我按住鼠标右键或中键时,它会变为 2 和 3 ...与事件属性按钮相同,按住鼠标左键与否...

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 ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文