iscroll使用遇到的兩個問題

滑動區域點擊按鈕會觸發兩次點擊事件

如下內容引用自CSDN論壇的foreveryang321用戶(原文連接:http://bbs.csdn.net/topics/390571943):dom


我也遇到這樣的問題,最後經過2次點擊時間差來解決。(500是2次點擊時間差,單位ms)
一、本身寫一個fn-->myclick,而後onclick="myclick();"調用。
代碼:
spa

JavaScript code?.net

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;
             }
         }
         /*本身的代碼*/
}


二、上面的代碼,也能夠寫在iscroll.js(4.2.5)的_end方法中,要注意var t1是全局的
三、國外論壇在iscroll.js(4.2.5)對應位置添加
code

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);


我用的是第1中方法,在每一個點擊的fn中都加入時間判斷代碼,這樣比較繁瑣,沒辦法,項目經理不給修改iscroll.js,建議直接在iscroll中加時間判斷。但願對你有幫助事件


往容器添加內容會致使頁面下半段閃爍

面對使用iscroll的頁面,若是頁面的dom結構發生變化,必定要調用scroll對象的refresh方法!
ip

相關文章
相關標籤/搜索