Simple implementation of Swiper touch sliding plug-in for imitation mobile

Source: Internet
Author: User

?/** * @author lyj * @Date 2016-02-04 * @Method sliding method for containers inside a large container do a sliding package * @param * args args.swipedom Large container object * args.swipety PE Sliding type * args.swipedistance buffer distance * Note: The high width of the sub-container is the height of the content being taken, so the size of the padding has an effect on */if (!window.itlyj) {window.itlyj = {};} Itlyj.iscroll = function (args) {/* * When not initialized at the time of invocation is initialized once */if (!    This instanceof Arguments.callee)) return new Arguments.callee (args); This.init (args);}; Itlyj.iScroll.prototype = {constructor:itlyj.iScroll, init:function (args) {/* * local variable to accept the current this*/var tha        t = this; /* If the incoming object is a DOM object, think of it as our big container box */if (args.swipedom && typeof args.swipedom = = ' object ') {THAT.P        Arentdom = Args.swipedom;        }/* Stop initializing */if (!that.parentdom) return FALSE if no parent container exists; /* Find child container */that.childdom = That.parentdom.children&&that.parentdom.children[0]?that.parentdom.children[0]:        ‘‘;        /* Stop initializing */if (!that.childdom) return False if no child container exists; /* Initialize incoming parameters */that.settings = {};        /* Default type Default y-axis slide if not Y then start with x-axis */That.settings.swipeType = args.swipetype?args.swipetype: ' Y ';        /* Default buffer sliding distance */that.settings.swipeDistance = args.swipedistance>=0?args.swipedistance:150;    /* Initialize slide */that._scroll ();        },/* Set positioning method for opening to the outside */settranslate:function (translate) {this.currpostion = translate;        This._addtransition ();    This._changetranslate (this.currpostion);        }, _addtransition:function () {this.childDom.style.transition = "all. 2s ease";        This.childDom.style.webkitTransition = "all. 2s ease";/* compatible with old version WebKit kernel browser */}, _removetransition:function () {        This.childDom.style.transition = "None";        This.childDom.style.webkitTransition = "none";/* compatible with old version WebKit kernel browser */}, _changetranslate:function (translate) {            if (This.settings.swipeType = = ' Y ') {this.childDom.style.transform = "Translatey (" +translate+ "px)"; This.childDom.style.webkitTransform = "Translatey ("+translate+ "px)";            }else{this.childDom.style.transform = "TranslateX (" +translate+ "px)";        This.childDom.style.webkitTransform = "TranslateX (" +translate+ "px)";        }}, _scroll:function () {/* local variable to accept the current this*/var that = this;        /* Type of swipe */var type = That.settings.swipeType = = ' y '? True:false;        /* height or width of parent container */var parentheight = type?that.parentdom.offsetheight:that.parentdom.offsetwidth;        /* Height or width of child container */var childheight = type?that.childdom.offsetheight:that.childdom.offsetwidth; /* Child container when no parent container is large */if (Childheight < parentheight) {if (type) {That.childDom.style.height                = parentheight + ' px ';            Childheight = Parentheight;                }else{that.childDom.style.width = parentheight + ' px ';            Childheight = Parentheight;        }}/* buffer distance */var distance = that.settings.swipeDistance; /* Zone */* left boxSub-positioning of the interval */that.maxpostion = 0;        That.minpostion =-(childheight-parentheight);        /* Set the current position of the slide */that.currpostion = 0;        that.startpostion = 0;        that.endpostion = 0;        that.movepostion = 0; /*1. Slide */that.childDom.addEventListener (' Touchstart ', function (e) {/* Initial y coordinates */that.startposti        on = Type?e.touches[0].clienty:e.touches[0].clientx;        },false);            That.childDom.addEventListener (' Touchmove ', function (e) {e.preventdefault ();            /* The value of the Endy recorded when the slide is being kept */that.endpostion = Type?e.touches[0].clienty:e.touches[0].clientx;            That.movepostion = that.startpostion-that.endpostion;/* calculates the distance to move *//*2. Sliding interval */* is the sliding zone */ if (that.currpostion-that.movepostion) < (that.maxpostion+distance) && (THAT.CURRP             Ostion-that.movepostion) > (that.minpostion-distance)) {that._removetransition ();   That._changetranslate (that.currpostion-that.movepostion);        }},false);            Window.addeventlistener (' Touchend ', function (e) {/* Re-calculates the current position after limiting the sliding interval */* To determine if it is within our reasonable positioning interval */ /* Swipe down first */if ((that.currpostion-that.movepostion) > that.maxpostion) {that.currpostion = th                At.maxpostion;                That._addtransition ();            That._changetranslate (that.currpostion); }/* When you want to swipe up */else if ((that.currpostion-that.movepostion) < that.minpostion) {that                . currpostion = that.minpostion;                That._addtransition ();            That._changetranslate (that.currpostion);            }/* Normal condition */else{that.currpostion = that.currpostion-that.movepostion;        } that._reset ();    },false);        }, _reset:function () {var = this;        that.startpostion = 0;     that.endpostion = 0;   that.movepostion = 0; }};?

  

Simple implementation of Swiper touch sliding plug-in for imitation mobile

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.