开发者

Javascript to use mouse click-hold to navigate?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜