模拟鼠标双击事件方法

  

doubleClick: function (o, fn) {
o.count = 0;
o.startTime = 0;
o.delay;
o.onmousedown = function () {
if (this.count == 0) {
this.startTime = new Date().getTime();
var that = this;
this.delay = setTimeout(function () {
that.count = 0;
that.startTime = 0;
}, 2000);
}
this.count++;
}
o.onmouseup = function () {
this.count++;
if (this.count >= 3) {
var shicha = new Date().getTime() - this.startTime;
this.count = 0;
this.startTime = 0;
if (shicha < 600) {
clearTimeout(this.delay);
fn.call(this, this);
return;
}
}
}
}

chrome IE9+ ff 的双击事件分解为 mousedown mouseup mousedown mouseup,IE8 分解为mousedown mouseup mouseup。IE6 7没测

posted @ 2014-02-24 17:25  winenr123  阅读(891)  评论(0编辑  收藏  举报