You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4 lines
7.0 KiB

/*! jQuery asScroll - v0.1.1 - 2015-05-11
* https://github.com/amazingSurge/jquery-asScroll
* Copyright (c) 2015 amazingSurge; Licensed GPL */
!function(a,b,c,d){"use strict";var e=0,f=function(){return"undefined"!=typeof a.performance&&a.performance.now?a.performance.now():Date.now()},g=function(a){return"string"==typeof a&&-1!==a.indexOf("%")},h=function(a){return parseFloat(a.slice(0,-1)/100,10)},i=function(){return a.requestAnimationFrame||a.webkitRequestAnimationFrame||a.mozRequestAnimationFrame||function(b){a.setTimeout(b,1e3/60)}}(),j=function(){return a.cancelAnimationFrame||a.webkitCancelAnimationFrame||a.mozCancelAnimationFrame||function(b){a.clearTimeout(b)}}(),k=function(a,b,c,d){function e(a,b){return 1-3*b+3*a}function f(a,b){return 3*b-6*a}function g(a){return 3*a}function h(a,b,c){return((e(b,c)*a+f(b,c))*a+g(b))*a}function i(a,b,c){return 3*e(b,c)*a*a+2*f(b,c)*a+g(b)}function j(b){for(var d=b,e=0;4>e;++e){var f=i(d,a,c);if(0===f)return d;var g=h(d,a,c)-b;d-=g/f}return d}return a===b&&c===d?{css:"linear",fn:function(a){return a}}:{css:"cubic-bezier("+a+","+b+","+c+","+d+")",fn:function(a){return h(j(a),b,d)}}},l=function(d,f){this.element=d,this.$element=c(d),this.options=c.extend(!0,{},l.defaults,f),this.options.containerSelector?this.$container=c(this.options.containerSelector):this.$container=this.$element.is(b.body)?c(a):this.$element.parent(),1===this.$container.length&&(this.namespace=this.options.namespace,this.attributes={vertical:{axis:"Y",overflow:"overflow-y",scroll:"scrollTop",scrollLength:"scrollHeight",pageOffset:"pageYOffset",ffPadding:"padding-right",length:"height",clientLength:"clientHeight",offsetLength:"offsetHeight",offset:"top",crossOffset:"left",crossLength:"width",crossClientLength:"clientWidth",crossOffsetLength:"offsetWidth"},horizontal:{axis:"X",overflow:"overflow-x",scroll:"scrollLeft",scrollLength:"scrollWidth",pageOffset:"pageXOffset",ffPadding:"padding-bottom",length:"width",clientLength:"clientWidth",offsetLength:"offsetWidth",offset:"left",crossOffset:"top",crossLength:"height",crossClientLength:"clientHeight",crossOffsetLength:"offsetHeight"}},this.classes={},this.easing=l.easing[this.options.easing]||l.easing.ease,this.duration=this.options.duration,this._frameId=null,this._states={},this.instanceId=++e,this.vertical=!1,this.horizontal=!1,this.init())};c.extend(l.easing={},{ease:k(.25,.1,.25,1),linear:k(0,0,1,1),"ease-in":k(.42,0,1,1),"ease-out":k(0,0,.58,1),"ease-in-out":k(.42,0,.58,1)}),l.prototype={constructor:l,getActiveTarget:function(a){if(this[a]){var b=this.getOffset(a),d=this.attributes[a],e=null,f=this.getContainerLength(a);return c.each(this.lists,function(a,c){var g=c.offset[d.offset],h=c.$el[d.length]();return g===b?(e=a,!1):g>b&&b+f>g?(e=a,!1):b>g&&g+h>b?(e=a,!0):g>b+f?!1:void 0}),e}},init:function(){var a=this;this.$targets=this.$element.find("[data-scroll-target]"),this.lists={},this.getScrollLength("vertical")>0&&(this.vertical=!0),this.getScrollLength("horizontal")>0&&(this.horizontal=!0),this.$targets.each(function(){var b=c(this);a.lists[b.data("scrollTarget")]={$el:b,offset:b.offset()}}),this.bindEvents()},bindEvents:function(){var b=this;c(a).on(this.eventNameWithId("resize"),function(){c(a).width()<b.options.mobile.width&&(b.duration=b.options.duration,b.easing=l.easing[b.options.easing]||l.easing.ease)}),c(a).on(this.eventNameWithId("orientationchange"),function(){c(a).width()<b.options.mobile.width&&(b.duration=b.options.duration,b.easing=l.easing[b.options.easing]||l.easing.ease)}),(this.horizontal||this.vertical)&&this.$container.on(this.eventName("scroll"),function(){b.vertical&&b.trigger(b.eventName("active"),["vertical",b.getActiveTarget("vertical")]),b.horizontal&&b.trigger(b.eventName("active"),["horizontal",b.getActiveTarget("horizontal")])})},eventName:function(a){if("string"!=typeof a||""===a)return"."+this.options.namespace;a=a.split(" ");for(var b=a.length,c=0;b>c;c++)a[c]=a[c]+"."+this.options.namespace;return a.join(" ")},eventNameWithId:function(a){if("string"!=typeof a||""===a)return this.options.namespace+"-"+this.instanceId;a=a.split(" ");for(var b=a.length,c=0;b>c;c++)a[c]=a[c]+"."+this.options.namespace+"-"+this.instanceId;return a.join(" ")},trigger:function(a){var