开发者

JQuery Distinction between quick Click event and a prolonged MouseDown

I'm trying to create a scrolling button that reacts differently to a quick click event than it does to a prolonged MouseDown (click and hold). The quick click event will scroll a specific number of pixels while click and hold will slowly scroll the pane until mouse up where it will stop.

This is what I have currently:

var mdown;
$('.next').bind('mousedown', function(event) {
    mdown = event.timeStamp;
    moving = setInterval(function(){
        $('#main').scrollLeft($('#main').scrollLeft() + 5);
    }, 1);
});
$('.next').bind('mouseup', function(event) {
    clearInterval(moving);
    if ((event.timeStamp - mdown) < 100) 
        $('#main').animate({ scrollLeft : '+=800'}, 500);
});

Is th开发者_如何学运维ere another way of doing this without comparing event timestamps? Is a click event treated any differently than mousedown/mouseup? Thanks!


Check this plugin(It defines an event to handle long clicks):

https://github.com/pisi/Longclick

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜