简体   繁体   English

使用鼠标单击保持导航的Javascript?

[英]Javascript to use mouse click-hold to navigate?

I have a scrollable div tag (overflow). 我有一个可滚动的div标签(溢出)。 Now I'd like to use mouse to click and hold and move to navigate up and down (like how the hand cursor feature in Adobe Reader works). 现在,我想使用鼠标单击并按住并移动来上下导航(例如Adobe Reader中的手形光标功能如何工作)。

Is there any js script to achieve this? 有没有实现此目的的js脚本? Specifically, I'm using jquery, any jquery plugins to achieve this? 具体来说,我正在使用jquery,是否有任何jquery插件来实现这一目标?

Don't know about any plugins but this shouldn't be too hard: 不知道任何插件,但这应该不难:

$(function() {
    $('#foo').mousedown(function(e) {
        var start = e.pageY;
        var startPos = $(this).scrollTop();
        var el = $(this);

        $().mousemove(function(e) {
            var offset = start - e.pageY;
            el.scrollTop(startPos + offset);
            return false;
        });

        $().one('mouseup', function(e) {
            $().unbind();
        });

        // Only if you want to prevent text selection
        return false;
    });
});

A working example can be found here: 一个有效的例子可以在这里找到:

http://www.ulmanen.fi/stuff/mousescroll.php http://www.ulmanen.fi/stuff/mousescroll.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM