| 12 |
- /*! shiwangyun.com */
- function Swipe(n,t){"use strict";function e(){h=x.children,m=h.length,2>h.length&&(t.continuous=!1),p.transitions&&t.continuous&&3>h.length&&(x.appendChild(h[0].cloneNode(!0)),x.appendChild(x.children[1].cloneNode(!0)),h=x.children),w=Array(h.length),g=n.getBoundingClientRect().width||n.offsetWidth,x.style.width=h.length*g+"px";for(var e=h.length;e--;){var i=h[e];i.style.width=g+"px",i.setAttribute("data-index",e),p.transitions&&(i.style.left=e*-g+"px",r(e,E>e?-g:e>E?g:0,0))}t.continuous&&p.transitions&&(r(a(E-1),-g,0),r(a(E+1),g,0)),p.transitions||(x.style.left=E*-g+"px"),n.style.visibility="visible"}function i(){t.continuous?s(E-1):E&&s(E-1)}function o(){t.continuous?s(E+1):h.length-1>E?s(E+1):s(0)}function a(n){return(h.length+n%h.length)%h.length}function s(n,e){if(E!=n){if(p.transitions){var i=Math.abs(E-n)/(E-n);if(t.continuous){var o=i;i=-w[a(n)]/g,i!==o&&(n=-i*h.length+n)}for(var s=Math.abs(E-n)-1;s--;)r(a((n>E?n:E)-s-1),g*i,0);n=a(n),r(E,g*i,e||b),r(n,0,e||b),t.continuous&&r(a(n-i),-(g*i),0)}else n=a(n),c(E*-g,n*-g,e||b);E=n,v(t.callback&&t.callback(E,h[E]))}}function r(n,t,e){d(n,t,e),w[n]=t}function d(n,t,e){var i=h[n],o=i&&i.style;o&&(o.webkitTransitionDuration=o.MozTransitionDuration=o.msTransitionDuration=o.OTransitionDuration=o.transitionDuration=e+"ms",o.webkitTransform="translate("+t+"px,0)"+"translateZ(0)",o.msTransform=o.MozTransform=o.OTransform="translateX("+t+"px)")}function c(n,e,i){if(!i)return x.style.left=e+"px",void 0;var o=+new Date,a=setInterval(function(){var s=+new Date-o;return s>i?(x.style.left=e+"px",$&&u(),t.transitionEnd&&t.transitionEnd.call(event,E,h[E]),clearInterval(a),void 0):(x.style.left=(e-n)*(Math.floor(100*(s/i))/100)+n+"px",void 0)},4)}function u(){$=t.auto||0,clearTimeout(T),T=setTimeout(o,$)}function l(){$=0,clearTimeout(T)}var f=function(){},v=function(n){setTimeout(n||f,0)},p={addEventListener:!!window.addEventListener,touch:"ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch,transitions:function(n){var t=["transitionProperty","WebkitTransition","MozTransition","OTransition","msTransition"];for(var e in t)if(void 0!==n.style[t[e]])return!0;return!1}(document.createElement("swipe"))};if(n){var h,w,g,m,x=n.children[0];t=t||{};var E=parseInt(t.startSlide,10)||0,b=t.speed||300;t.continuous=void 0!==t.continuous?t.continuous:!0;var T,y,$=t.auto||0,k={},L={},O={handleEvent:function(n){switch(n.type){case"touchstart":this.start(n);break;case"touchmove":this.move(n);break;case"touchend":v(this.end(n));break;case"webkitTransitionEnd":case"msTransitionEnd":case"oTransitionEnd":case"otransitionend":case"transitionend":v(this.transitionEnd(n));break;case"resize":v(e)}t.stopPropagation&&n.stopPropagation()},start:function(n){var t=n.touches[0];k={x:t.pageX,y:t.pageY,time:+new Date},y=void 0,L={},x.addEventListener("touchmove",this,!1),x.addEventListener("touchend",this,!1)},move:function(n){if(!(n.touches.length>1||n.scale&&1!==n.scale)){t.disableScroll&&n.preventDefault();var e=n.touches[0];L={x:e.pageX-k.x,y:e.pageY-k.y},y===void 0&&(y=!!(y||Math.abs(L.x)<Math.abs(L.y))),y||(n.preventDefault(),l(),t.continuous?(d(a(E-1),L.x+w[a(E-1)],0),d(E,L.x+w[E],0),d(a(E+1),L.x+w[a(E+1)],0)):(L.x=L.x/(!E&&L.x>0||E==h.length-1&&0>L.x?Math.abs(L.x)/g+1:1),d(E-1,L.x+w[E-1],0),d(E,L.x+w[E],0),d(E+1,L.x+w[E+1],0)))}},end:function(){var n=+new Date-k.time,e=250>Number(n)&&Math.abs(L.x)>20||Math.abs(L.x)>g/2,i=!E&&L.x>0||E==h.length-1&&0>L.x;t.continuous&&(i=!1);var o=0>L.x;y||(e&&!i?(o?(t.continuous?(r(a(E-1),-g,0),r(a(E+2),g,0)):r(E-1,-g,0),r(E,w[E]-g,b),r(a(E+1),w[a(E+1)]-g,b),E=a(E+1)):(t.continuous?(r(a(E+1),g,0),r(a(E-2),-g,0)):r(E+1,g,0),r(E,w[E]+g,b),r(a(E-1),w[a(E-1)]+g,b),E=a(E-1)),t.callback&&t.callback(E,h[E])):t.continuous?(r(a(E-1),-g,b),r(E,0,b),r(a(E+1),g,b)):(r(E-1,-g,b),r(E,0,b),r(E+1,g,b))),x.removeEventListener("touchmove",O,!1),x.removeEventListener("touchend",O,!1)},transitionEnd:function(n){parseInt(n.target.getAttribute("data-index"),10)==E&&($&&u(),t.transitionEnd&&t.transitionEnd.call(n,E,h[E]))}};return e(),$&&u(),p.addEventListener?(p.touch&&x.addEventListener("touchstart",O,!1),p.transitions&&(x.addEventListener("webkitTransitionEnd",O,!1),x.addEventListener("msTransitionEnd",O,!1),x.addEventListener("oTransitionEnd",O,!1),x.addEventListener("otransitionend",O,!1),x.addEventListener("transitionend",O,!1)),window.addEventListener("resize",O,!1)):window.onresize=function(){e()},{setup:function(){e()},slide:function(n,t){l(),s(n,t)},prev:function(){l(),i()},begin:function(){l(),u()},next:function(){l(),o()},stop:function(){l()},getPos:function(){return E},getNumSlides:function(){return m},kill:function(){l(),x.style.width="",x.style.left="";for(var n=h.length;n--;){var t=h[n];t.style.width="",t.style.left="",p.transitions&&d(n,0,0)}p.addEventListener?(x.removeEventListener("touchstart",O,!1),x.removeEventListener("webkitTransitionEnd",O,!1),x.removeEventListener("msTransitionEnd",O,!1),x.removeEventListener("oTransitionEnd",O,!1),x.removeEventListener("otransitionend",O,!1),x.removeEventListener("transitionend",O,!1),window.removeEventListener("resize",O,!1)):window.onresize=null}}}}(window.jQuery||window.Zepto)&&function(n){n.fn.Swipe=function(t){return this.each(function(){n(this).data("Swipe",new Swipe(n(this)[0],t))})}}(window.jQuery||window.Zepto);
|