jQuery 三击事件实现代码
直接给出代码如下:
jQuery.event.special.tripleclick = {
setup: function(data, namespaces) {
var elem = this, $elem = jQuery(elem);
$elem.bind('click', jQuery.event.special.tripleclick.handler);
},
teardown: function(namespaces) {
var elem = this, $elem = jQuery(elem);
$elem.unbind('click', jQuery.event.special.tripleclick.handler);
},
handler: function(event) {
var elem = this, $elem = jQuery(elem), clicks = $elem.data('clicks') || 0;
clicks += 1;
if ( clicks === 3 ) {
clicks = 0;
// set event type to "tripleclick"
event.type = "tripleclick";
// let jQuery handle the triggering of "tripleclick" event handlers
jQuery.event.handle.apply(this, arguments)
}
$elem.data('clicks', clicks);
}
};
调用时:
$('#div').bind('tripleclick', function (event) {
//do something
});
上一篇:jQuery实现简单弹幕制作
栏 目:jquery
下一篇:jQuery(1.3.2) 7行代码搞定跟随屏幕滚动的层
本文标题:jQuery 三击事件实现代码
本文地址:http://www.codeinn.net/misctech/168208.html