Component-Builder/admin/custom/uikit/js/components/grid-parallax.min.js

2 lines
2.0 KiB
JavaScript

/*! UIkit 2.27.4 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
!function(t){var n;window.UIkit2&&(n=t(UIkit2)),"function"==typeof define&&define.amd&&define("uikit-grid-parallax",["uikit"],function(){return n||t(UIkit2)})}(function(t){function n(t){for(var n=t.children(),i=n.filter(":visible:first"),e=i[0].offsetTop+i.outerHeight(),o=0;o<n.length&&!(n[o].offsetTop>=e);o++);return o||1}function i(n){var i,e,o,r=n.offset().top,s=n.outerHeight(),a=t.$win.scrollTop(),l=window.innerHeight;return r>a+l?o=0:a>r+s?o=1:(l>r+s?o=(l>a?a:a-l)/(r+s):(i=a+l-r,e=Math.round(i/((l+s)/100)),o=e/100),l>r&&(o=o*a/(r+s-l))),o>1?1:o}var e=[],o=function(){requestAnimationFrame(function(){for(var t=0;t<e.length;t++)e[t].process()})};t.component("gridparallax",{defaults:{target:!1,smooth:150,translate:150},boot:function(){t.$doc.on("scrolling.uk.document",o),t.$win.on("load resize orientationchange",t.Utils.debounce(function(){o()},50)),t.ready(function(n){t.$("[data-uk-grid-parallax]",n).each(function(){var n=t.$(this);n.data("gridparallax")||t.gridparallax(n,t.Utils.options(n.attr("data-uk-grid-parallax")))})})},init:function(){var i=this;this.initItems().process(),e.push(this),t.$win.on("load resize orientationchange",function(){var e=function(){var t=n(i.element);i.element.css("margin-bottom",""),t>1&&i.element.css("margin-bottom",i.options.translate+parseInt(i.element.css("margin-bottom")))};return t.$(function(){e()}),t.Utils.debounce(e,50)}())},initItems:function(){var n=this.options.smooth;return this.items=(this.options.target?this.element.find(this.options.target):this.element.children()).each(function(){t.$(this).css({transition:"transform "+n+"ms linear",transform:""})}),this},process:function(){var e=i(this.element),o=n(this.element),r=this.items,s=[o-1];if(1==o||!e)return r.css("transform",""),void 0;for(;s.length<o&&s[s.length-1]-2;)s.push(s[s.length-1]-2);var a=this.options.translate,l=e*a;r.each(function(n,i,e){e=-1!=s.indexOf((n+1)%o)?l:l/8,t.$(this).css("transform","translate3d(0,"+e+"px, 0)")})}})});