开发者

Javascript to use mouse click-hold to navigate?

开发者 https://www.devze.com 2022-12-23 15:31 出处:网络
I have a scrollable div tag (overflow). 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).

I have a scrollable div tag (overflow). 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).

Is there any js script to achieve this? Specifically, I'm using jquery, any jquery plugins to achieve this?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号