Sfoglia il codice sorgente

优化iscroll在ios webview顶部滑出不触发滑动结束事件

guohh 6 anni fa
parent
commit
83623fd4c7
1 ha cambiato i file con 27 aggiunte e 8 eliminazioni
  1. 27 8
      ipuui/demo/dep/js/iscroll/iscroll.js

+ 27 - 8
ipuui/demo/dep/js/iscroll/iscroll.js

@ -1,6 +1,7 @@
1 1
/*!
2 2
 * iScroll v4.2.5 ~ Copyright (c) 2012 Matteo Spinelli, http://cubiq.org
3 3
 * Released under MIT license, http://cubiq.org/license
4
 * 非官方原始版本,已优化处理
4 5
 */
5 6
(function (window, doc) {
6 7
  var m = Math,
@ -35,6 +36,10 @@
35 36
    isIDevice = (/iphone|ipad/gi).test(navigator.appVersion),
36 37
    isTouchPad = (/hp-tablet/gi).test(navigator.appVersion),
37 38
39
  // add by ipu 判断是否webview环境
40
    ua = navigator.userAgent,
41
    webApp = ua.indexOf('Safari') == -1,  //是否web应该程序,没有头部与底部
42
38 43
    has3d = prefixStyle('perspective') in dummyStyle,
39 44
    hasTouch = 'ontouchstart' in window && !isTouchPad,
40 45
    hasTransform = vendor !== false,
@ -97,8 +102,8 @@
97 102
98 103
      // Default options
99 104
      that.options = {
100
        hScroll: true,
101
        vScroll: true,
105
        hScroll: true,    // 纵向滚动
106
        vScroll: true,    // 垂直滚动
102 107
        x: 0,
103 108
        y: 0,
104 109
        bounce: true,
@ -112,8 +117,8 @@
112 117
        handleClick: false,
113 118
114 119
        // Scrollbar
115
        hScrollbar: true,
116
        vScrollbar: true,
120
        hScrollbar: true,   // 是否显示纵向滚动条
121
        vScrollbar: true,   // 是否显示垂直滚动条
117 122
        fixedScrollbar: isAndroid,
118 123
        hideScrollbar: isIDevice,
119 124
        fadeScrollbar: isIDevice && has3d,
@ -156,8 +161,8 @@
156 161
      for (i in options) that.options[i] = options[i];
157 162
158 163
      // Set starting position
159
      that.x = that.options.x;
160
      that.y = that.options.y;
164
      that.x = that.options.x;      // 初始位置
165
      that.y = that.options.y;      // 初始位置
161 166
162 167
      // Normalize options
163 168
      that.options.useTransform = hasTransform && that.options.useTransform;
@ -445,6 +450,20 @@
445 450
        c1, c2, scale,
446 451
        timestamp = e.timeStamp || Date.now();
447 452
453
      // add by ipu,
454
      // ios webview环境:往上滑动到达顶部工具栏后,不触发touchend,需手动触发touchend
455
      // 参考:https://segmentfault.com/q/1010000002943205
456
      // 判断为ios webview环境,且超出webview窗口范围
457
      if (!isAndroid && webApp && e.changedTouches[0].pageY <= 0) {
458
        e.preventDefault();
459
        that._unbind("touchmove", window);
460
        var cancelEvent = new Event(CANCEL_EV);
461
        cancelEvent.touches = [];
462
        cancelEvent.changedTouches = e.changedTouches;
463
        window.dispatchEvent(cancelEvent);
464
        return;
465
      }
466
448 467
      if (that.options.onBeforeScrollMove) that.options.onBeforeScrollMove.call(that, e);
449 468
450 469
      // Zoom
@ -895,11 +914,11 @@
895 914
    },
896 915
897 916
    _bind: function (type, el, bubble) {
898
      (el || this.scroller).addEventListener(type, this, {capture:!!bubble, passive: false});
917
      (el || this.scroller).addEventListener(type, this, {capture: !!bubble, passive: false});
899 918
    },
900 919
901 920
    _unbind: function (type, el, bubble) {
902
      (el || this.scroller).removeEventListener(type, this, {capture:!!bubble, passive: false});
921
      (el || this.scroller).removeEventListener(type, this, {capture: !!bubble, passive: false});
903 922
    },
904 923
905 924