jQuery Gestures

javascript Add comments

基于jQuery的鼠标手势支持,由于使用了canvas所以对IE 支持不好。

// initialize the engine, inactive by default and set the trace color to red
$.gestures.init({active:false,color:‘#ff0000′});
// adds a new gesture : Down
$.gestures.register(‘D’, function() {
alert(‘down !’);
});

// a more complex gesture : Down, Left, Up, Right
$.gestures.register(‘DLUR’, function() {
alert(‘this is a rectangle, no ?’);
});

// you can log unknown gestures :
$.gestures.error(function(gesture) {
alert(“oops, I don’t understand what \”+gesture+\” means”);
});

// useful keyboard tricks :
$(window).keydown(function(e) {
if ($.gestures.active() && e.which==27) {
// disable capture when user presses ESC
$.gestures.disable();
} else if (!$.gestures.active() && e.which==17) {
// enable capture when CTRL is pressed
$.gestures.enable();
}
});
$(window).keyup(function(e) {
// disable capture when CTRL is not pressed
if ($.gestures.active() && e.which==17) {
$.gestures.disable();
}
});

从上面的代码中可以看出,一开始初始化gestures,然后通过register注册鼠标手势,后面几个keyup通过判断是否按下CTRL或ESC启用或禁用全局鼠标手势。

Link:  jQuery Gestures

Demo: jQuery-gestures- Image gallery

Download: jquery.gestures.js

  • Share/Bookmark

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

2 Responses to “jQuery Gestures”

  1. Chouxinxin Says:

    链接加起来,你娃现在哪里混~

  2. smilebug Says:

    还不是在那地方混,有啥好地方介绍介绍撒

Leave a Reply


WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in