iscroll滑动区域内的div onclick事件单击一次触发了两次bug解决

1、自己写一个fn-->myclick,然后οnclick="myclick();"调用。
代码:
JavaScript code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var  t1 =  null ; //这个设置为全局
function  myclick(){
     if  (t1 ==  null ){
         t1 =  new  Date().getTime();
     } else {       
         var  t2 =  new  Date().getTime();
         if (t2 - t1 < 500){
             t1 = t2;
             return ;
         } else {
             t1 = t2;
         }
     }
     /*自己的代码*/
}

2、上面的代码,也可以写在iscroll.js(4.2.5)的_end方法中,要注意var t1是全局的
3、国外论坛在iscroll.js(4.2.5)对应位置添加
JavaScript code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
topOffset: 0,
checkDOMChanges:  false ,    // Experimental
handleClick:  true ,
preventGhostClick:  false // prevent ghost clicks?防止2次点击
ghostClickTimeout: 500,    // timeout for ghost click prevention设置时间差
 
/**
* Prevents any real clicks.
* See preventGhostClick portion of _end().
*/
_preventRealClick:  function (e) {
     if  (e._fake !==  true ) {
         e.preventDefault();
         e.stopPropagation();
         e.stopImmediatePropagation();
         e.cancel =  true ;
         return  false ;
     }
},
_end:  function  (e) {......
 
ev._fake =  true ;
if  (that.options.preventGhostClick) {  //preventGhostClick: true,
     // prevent ghost real clicks on body
     document.body.addEventListener( 'click' , that._preventRealClick,  true );
     // until ghost click timeout expires
     setTimeout( function  () {
               document.body.removeEventListener( 'click' , that._preventRealClick,  true );
     }, that.options.ghostClickTimeout);
}
target.dispatchEvent(ev);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值