The Iscroll Click event Triggers the solution of two times __javascript

Source: Internet
Author: User
Tags abs pow wrapper

Iscroll actually intercepts the Touchstart and Touchend events when clicking on the browser. In Touchend, use JS to trigger the element's OnClick event (_end this function). In practice, the touchend is executed first and then the correlation function of the onclick is executed. This creates a two-click trigger for a headache.

There are a lot of code on the Internet to solve the "Iscroll Click event" Click a trigger two times, I also follow the steps of the great God to write, but still not successful, it may be the operation is not right, I attach my execution code, I have been successful.



Solution 1: Click the event using Zepto tap to resolve it.


Solution 2: That.doubletaptimer The Iscroll search to comment out or directly annotate the following 557-573 lines.

/*! * Iscroll v4.2.5 ~ Copyright (c) Matteo Spinelli, Http://cubiq.org * released under MIT license, http://cubiq.org/li  Cense */function (window, doc) {var m = Math, Dummystyle = doc.createelement (' div '). Style, vendor = (function () {var vendors = ' T,webkitt,mozt,mst,ot '. Split (', '), t, i = 0, L = Vendors.len

        Gth
            for (; I < L; i++) {t = vendors[i] + ' ransform ';
            if (t in Dummystyle) {return vendors[i].substr (0, vendors[i].length-1);
    return false; }) (), Cssvendor = Vendor? '-' + vendor.tolowercase () + '-': ',//Style Properties Transform = Prefixstyle (' transform '), TRANSITIONPR Operty = Prefixstyle (' Transitionproperty '), transitionduration = Prefixstyle (' transitionduration '), TransformOrigi n = Prefixstyle (' Transformorigin '), transitiontimingfunction = Prefixstyle (' transitiontimingfunction '), transItiondelay = Prefixstyle (' Transitiondelay '),//Browser capabilities isandroid = (/ANDROID/GI). Test (Navigator.app Version), Isidevice = (/iphone|ipad/gi). Test (navigator.appversion), Istouchpad = (/hp-tablet/gi). Test (Navigator.ap pversion), Has3d = Prefixstyle (' perspective ') in Dummystyle, Hastouch = ' ontouchstart ' in window &&!isto Uchpad, Hastransform = Vendor!== false, Hastransitionend = Prefixstyle (' transition ') in Dummystyle, resize_e V = ' onorientationchange ' in window? ' Orientationchange ': ' resize ', Start_ev = Hastouch? ' Touchstart ': ' MouseDown ', Move_ev = Hastouch? ' Touchmove ': ' MouseMove ', End_ev = Hastouch? ' Touchend ': ' MouseUp ', Cancel_ev = Hastouch?

        ' Touchcancel ': ' MouseUp ', Trnend_ev = (function () {if (vendor = = false) return false;
                var transitionend = {': ' transitionend ', ' webkit ': ' Webkittransitionend ',     ' Moz '  : ' Transitionend ', ' O ': ' otransitionend ', ' ms ': ' Mstransitionend '

        };
    return Transitionend[vendor];
            }) (), NextFrame = (function () {return Window.requestanimationframe | |
            Window.webkitrequestanimationframe | |
            Window.mozrequestanimationframe | |
            Window.orequestanimationframe | |
            Window.msrequestanimationframe | |
    Function (callback) {return settimeout (callback, 1);};
            }) (), Cancelframe = (function () {return Window.cancelrequestanimationframe | |
            Window.webkitcancelanimationframe | |
            Window.webkitcancelrequestanimationframe | |
            Window.mozcancelrequestanimationframe | |
            Window.ocancelrequestanimationframe | |
            Window.mscancelrequestanimationframe | |
    cleartimeout; }) (),//Helpers Translatez = has3d? ' Translatez (0) ': ',//constructor ISCROll = function (el, options) {var = this, I; That.wrapper = typeof el = = ' object '?
        El:doc.getElementById (EL);
        That.wrapper.style.overflow = ' hidden ';

        That.scroller = that.wrapper.children[0];
            Default options that.options = {hscroll:true, vscroll:true, x:0, y:0, Bounce:true, Bouncelock:false, Momentum:true, lockdirection : True, Usetransform:true, Usetransition:false, topoffset:0, CHECKDOMCH
            Anges:false,//experimental handleclick:true,//Scrollbar hscrollbar:true, Vscrollbar:true, Fixedscrollbar:isandroid, Hidescrollbar:isidevice, fade
            Scrollbar:isidevice && has3d, Scrollbarclass: ',//Zoom Zoom:false, ZoommiN:1, Zoommax:4, Doubletapzoom:2, wheelaction: ' scroll ',//Snap Snap:false, Snapthreshold:1,//Events Onrefresh:null, Onbefores
            Crollstart:null, Onscrollstart:null, Onbeforescrollmove:null, Onscrollmove:null, Onbeforescrollend:null, Onscrollend:null, Ontouchend:null, Ondestroy:nu

        ll, Onzoomstart:null, Onzoom:null, onzoomend:null};

        User defined options for (i in options) that.options[i] = options[i];
        Set starting position that.x = that.options.x;

        That.y = That.options.y;
        Normalize options that.options.useTransform = Hastransform && that.options.useTransform;
        That.options.hScrollbar = That.options.hScroll && that.options.hScrollbar; That.oPtions.vscrollbar = That.options.vScroll && that.options.vScrollbar;
        That.options.zoom = That.options.useTransform && that.options.zoom;

        That.options.useTransition = Hastransitionend && that.options.useTransition;
        Helpers FIX ANDROID bug!
        Translate3d and scale doesn ' t work together! Ignoring 3d only when you SET that.options.zoom if (that.options.zoom && isandroid) {Tran
        Slatez = '; }//Set Some default styles that.scroller.style[transitionproperty] = That.options.useTransform?
        Cssvendor + ' transform ': ' top left ';
        That.scroller.style[transitionduration] = ' 0 ';
        That.scroller.style[transformorigin] = ' 0 0 ';

        if (that.options.useTransition) that.scroller.style[transitiontimingfunction] = ' cubic-bezier (0.33,0.66,0.66,1) '; if (that.options.useTransform) that.scroller.style[transform] = ' translate (' + that.x + ' px, ' + that.y + ' px) ' + Translatez;

        else That.scroller.style.cssText = ';p osition:absolute;top: ' + that.y + ' Px;left: ' + that.x + ' px ';

        if (that.options.useTransition) That.options.fixedScrollbar = true;

        That.refresh ();
        That._bind (Resize_ev, window);
        That._bind (Start_ev);
                if (!hastouch) {if (that.options.wheelAction!= ' None ') {that._bind (' dommousescroll ');
            That._bind (' MouseWheel '); } if (that.options.checkDOMChanges) that.checkdomtime = setinterval (function () {That._che
        Ckdomchanges ();
    }, 500);

}; Prototype Iscroll.prototype = {enabled:true, x:0, y:0, steps: [], Scale:1, currpagex:0, C
        urrpagey:0, PagesX: [], PagesY: [], Anitime:null, wheelzoomcount:0, Handleevent:function (e) {
        var that = this; Switch (e.type) {case start_ev:if (!hastouch && E.buTton!== 0) return;
                That._start (e);
            Break Case Move_ev:that._move (e);
            Break Case End_ev:case Cancel_ev:that._end (e);
            Break Case Resize_ev:that._resize ();
            Break Case ' Dommousescroll ': Case ' MouseWheel ': That._wheel (e);
            Break Case Trnend_ev:that._transitionend (e);
        Break
            }, _checkdomchanges:function () {if (this.moved | | this.zoomed | | this.animating | | (This.scrollerw = this.scroller.offsetWidth * This.scale && This.scrollerh = = This.scroller.offsetHeight * This

        . scale)) return;
    This.refresh ();

        }, _scrollbar:function (dir) {var that = this, bar; if (!that[dir + ' Scrollbar ']) {if (That[dir + ' scrollbarwrapper ']) {if (hastransform) that[d
                IR + ' scrollbarindicator '].style[transform] = '; That[dir + ' Scrollbarwrapper '].parentnode.removecHild (That[dir + ' scrollbarwrapper ']);
                That[dir + ' scrollbarwrapper '] = null;
            That[dir + ' scrollbarindicator '] = null;
        } return; } if (!that[dir + ' scrollbarwrapper ']) {*//Create the ScrollBar wrapper b

            AR = doc.createelement (' div ');
            if (that.options.scrollbarClass) Bar.classname = That.options.scrollbarClass + dir.touppercase (); else Bar.style.cssText = ' position:absolute;z-index:100 ' + (dir = = ' h '?) ' Height:7px;bottom:1px;left:2px;right: ' + (That.vscrollbar? ' 7 ': ' 2 ') + ' px ': ' Width:7px;bottom: ' + (That.hscrollbar?

            ' 7 ': ' 2 ') + ' px;top:2px;right:1px '); Bar.style.cssText = ';p ointer-events:none; ' + Cssvendor + ' transition-property:opacity; ' + Cssvendor + ' Transition-duration: ' + (That.options.fadeScrollbar? ' 350ms ': ' 0 ') + ' overflow:hidden;opacity: ' + (That.options.hideScrollbar?

            ' 0 ': ' 1 '); That.wrapper.appendChilD (bar);

            That[dir + ' scrollbarwrapper '] = bar;
            Create the scrollbar indicator bar = doc.createelement (' div '); if (!that.options.scrollbarclass) {bar.style.cssText = ' Position:absolute;z-index:100;background:rgba ' (0,0 , 0,0.5); border:1px solid Rgba (255,255,255,0.9); ' + Cssvendor + ' background-clip:padding-box; ' + Cssvendor + ' box-sizing: Border-box ' + (dir = = ' h '?)
            ' height:100% ': ' width:100% ') + '; ' + Cssvendor + ' border-radius:3px;border-radius:3px ';  Bar.style.cssText + = ';p ointer-events:none; ' + Cssvendor + ' Transition-property: ' + Cssvendor + ' transform; ' + Cssvendor + ' transition-timing-function:cubic-bezier (0.33,0.66,0.66,1); ' + Cssvendor + ' transition-duration:0; ' +
            Cssvendor + ' transform:translate (0,0) ' + Translatez; if (that.options.useTransition) bar.style.cssText = '; ' + Cssvendor + ' Transition-timing-function:cubic-bezier (

            0.33,0.66,0.66,1) '; That[dir + ' ScrolLbarwrapper '].appendchild (bar);
            That[dir + ' scrollbarindicator '] = bar;
            * * * Remove scroll bar 2016-08-26 yubai8*/bar = doc.createelement (' div ');
            That[dir + ' scrollbarwrapper '] = bar;

        That[dir + ' scrollbarindicator '] = bar;
            } if (dir = = ' h ') {that.hscrollbarsize = That.hScrollbarWrapper.clientWidth;
            That.hscrollbarindicatorsize = M.max (M.round (that.hscrollbarsize * that.hscrollbarsize/that.scrollerw), 8);
            That.hScrollbarIndicator.style.width = that.hscrollbarindicatorsize + ' px ';
            That.hscrollbarmaxscroll = that.hscrollbarsize-that.hscrollbarindicatorsize;
        That.hscrollbarprop = THAT.HSCROLLBARMAXSCROLL/THAT.MAXSCROLLX;
            else {that.vscrollbarsize = That.vScrollbarWrapper.clientHeight;
            That.vscrollbarindicatorsize = M.max (M.round (that.vscrollbarsize * that.vscrollbarsize/that.scrollerh), 8); That.vScrollbarIndicator.style.height = that.vscrollbarindicatorsize + ' px ';
            That.vscrollbarmaxscroll = that.vscrollbarsize-that.vscrollbarindicatorsize;
        That.vscrollbarprop = that.vscrollbarmaxscroll/that.maxscrolly;
    }//Reset position That._scrollbarpos (dir, true);
        }, _resize:function () {var that = this;
    settimeout (function () {That.refresh ();}, isandroid? 200:0);

        }, _pos:function (x, y) {if (this.zoomed) return; x = This.hscroll?
        x:0; y = this.vscroll?

        y:0; if (this.options.useTransform) {This.scroller.style[transform] = ' translate (' + x + ' px, ' + y + ' px ') scale ('
        + This.scale + ') ' + Translatez;
            else {x = M.round (x);
            y = M.round (y);
            This.scroller.style.left = x + ' px ';
        This.scroller.style.top = y + ' px ';
        } this.x = x;

        This.y = y; This._scrollbarpos(' H ');
    This._scrollbarpos (' V ');
            }, _scrollbarpos:function (dir, hidden) {var that = this, pos = Dir = = ' h '? That.x:that.y,

        Size

        if (!that[dir + ' Scrollbar ']) return;

        pos = that[dir + ' Scrollbarprop '] * POS; if (POS < 0) {if (!that.options.fixedscrollbar) {size = That[dir + ' Scrollbarindicatorsiz
                E '] + m.round (POS * 3);
                if (Size < 8) size = 8; That[dir + ' scrollbarindicator '].style[dir = = ' h '?
            ' Width ': ' height ' = size + ' px ';
        pos = 0; else if (pos > That[dir + ' scrollbarmaxscroll ']) {if (!that.options.fixedscrollbar) {si
                Ze = that[dir + ' scrollbarindicatorsize ']-m.round ((Pos-that[dir + ' scrollbarmaxscroll ']) * 3);
                if (Size < 8) size = 8; That[dir + ' scrollbarindicator '].style[dir = = ' h '?
         ' Width ': ' height ' = size + ' px ';       pos = that[dir + ' Scrollbarmaxscroll '] + (That[dir + ' scrollbarindicatorsize ']-size);
            else {pos = that[dir + ' scrollbarmaxscroll '];
        } that[dir + ' Scrollbarwrapper '].style[transitiondelay] = ' 0 '; That[dir + ' scrollbarwrapper '].style.opacity = hidden && that.options.hideScrollbar?
        ' 0 ': ' 1 '; That[dir + ' scrollbarindicator '].style[transform] = ' translate (' + (dir = = ' h '? pos + ' px,0 ') ': ' 0, ' + pos + ' px ') + tra
    Nslatez; }, _start:function (e) {var "= this", point = Hastouch? E.touches[0]: E, Matri

        x, x, y, C1, C2;

        if (!that.enabled) return;

        if (That.options.onBeforeScrollStart) That.options.onBeforeScrollStart.call (that, e);

        if (that.options.useTransition | | that.options.zoom) that._transitiontime (0);
        That.moved = false;
        That.animating = false;
        That.zoomed = false; That.distx= 0;
        that.disty = 0;
        THAT.ABSDISTX = 0;
        that.absdisty = 0;
        That.dirx = 0;

        That.diry = 0; Gesture start if (that.options.zoom && hastouch && e.touches.length > 1) {c1 =
            M.abs (E.touches[0].pagex-e.touches[1].pagex);
            C2 = M.abs (E.touches[0].pagey-e.touches[1].pagey);

            That.touchesdiststart = M.SQRT (C1 * c1 + c2 * c2);
            That.originx = M.abs (E.touches[0].pagex + e.touches[1].pagex-that.wrapperoffsetleft * 2)/2-that.x;

            That.originy = M.abs (E.touches[0].pagey + e.touches[1].pagey-that.wrapperoffsettop * 2)/2-that.y;
        if (That.options.onZoomStart) That.options.onZoomStart.call (that, e); } if (that.options.momentum) {if (that.options.useTransform) {//Very lame General Purpose alternative to Cssmatrix matrix = getComputedStyle (That.scroller, null) [Transform].replace (/[^0-9\-.,]/g, '). Split (', ');
                x = + (matrix[12] | | matrix[4]);
            y = + (matrix[13] | | matrix[5]);
                else {x = +getcomputedstyle (That.scroller, null). Left.replace (/[^0-9-]/g, ");
            y = +getcomputedstyle (That.scroller, null). Top.replace (/[^0-9-]/g, ");
                } if (x!= that.x | | y!= that.y) {if (that.options.useTransition) that._unbind (Trnend_ev);
                else Cancelframe (that.anitime);
                That.steps = [];
                That._pos (x, y);
            if (that.options.onScrollEnd) that.options.onScrollEnd.call (that);    } that.absstartx = That.x;

        Needed by snap threshold that.absstarty = That.y;
        That.startx = That.x;
        That.starty = That.y;
        That.pointx = Point.pagex;

        That.pointy = Point.pagey; That.starttime = E.timestamp | |

        Date.now (); if (that.options.onScrollStart) thaT.options.onscrollstart.call (that, e);
        That._bind (Move_ev, window);
        That._bind (End_ev, window);
    That._bind (Cancel_ev, window);  }, _move:function (e) {var "= this", point = Hastouch? E.touches[0]: E, DeltaX
            = Point.pagex-that.pointx, DeltaY = point.pagey-that.pointy, newx = That.x + DeltaX, Newy = That.y + DeltaY, C1, c2, scale, timestamp = E.timestamp |

        Date.now ();

        if (That.options.onBeforeScrollMove) That.options.onBeforeScrollMove.call (that, e); Zoom if (that.options.zoom && hastouch && e.touches.length > 1) {c1 = M.abs (e.t
            Ouches[0].pagex-e.touches[1].pagex);
            C2 = M.abs (E.touches[0].pagey-e.touches[1].pagey);

            That.touchesdist = M.sqrt (C1*C1+C2*C2);

            That.zoomed = true;

Scale = 1/that.touchesdiststart * that.touchesdist * this.scale;            if (Scale < that.options.zoomMin) Scale = 0.5 * That.options.zoomMin * MATH.POW (2.0, Scale/that.options.z
            Oommin); else if (Scale > That.options.zoomMax) scale = 2.0 * That.options.zoomMax * MATH.POW (<

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.