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.
 
 

3 lines
4.9 KiB

/*! UIkit 3.0.0-rc.17 | http://www.getuikit.com | (c) 2014 - 2018 YOOtheme | MIT License */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("uikit-util")):"function"==typeof define&&define.amd?define("uikitparallax",["uikit-util"],t):e.UIkitParallax=t(e.UIkit.util)}(this,function(v){"use strict";var e={props:{media:Boolean},data:{media:!1},computed:{matchMedia:function(){var e=function(e){if(v.isString(e))if("@"===e[0]){var t="breakpoint-"+e.substr(1);e=v.toFloat(v.getCssVar(t))}else if(isNaN(e))return e;return!(!e||isNaN(e))&&"(min-width: "+e+"px)"}(this.media);return!e||window.matchMedia(e).matches}}};var t=["x","y","bgx","bgy","rotate","scale","color","backgroundColor","borderColor","opacity","blur","hue","grayscale","invert","saturate","sepia","fopacity"];function m(e,t){var r=e.length-1,i=Math.min(Math.floor(r*t),r-1),a=e.slice(i,i+2);return a.push(1===t?1:t%(1/r)*r),a}function k(e,t,r){void 0===r&&(r=2);var i=m(e,t),a=i[0],s=i[1],n=i[2];return(v.isNumber(a)?a+Math.abs(a-s)*n*(a<s?1:-1):+s).toFixed(r)}var r={mixins:[{mixins:[e],props:t.reduce(function(e,t){return e[t]="list",e},{}),data:t.reduce(function(e,t){return e[t]=void 0,e},{}),computed:{props:function(p,h){var g=this;return t.reduce(function(e,t){if(v.isUndefined(p[t]))return e;var r,i,a,s=t.match(/color/i),n=s||"opacity"===t,o=p[t].slice(0);n&&v.css(h,t,""),o.length<2&&o.unshift(("scale"===t?1:n?v.css(h,t):0)||0);var c=v.includes(o.join(""),"%")?"%":"px";if(s){var u=h.style.color;o=o.map(function(e){return t=h,r=e,v.css(v.css(t,"color",r),"color").split(/[(),]/g).slice(1,-1).concat(1).slice(0,4).map(function(e){return v.toFloat(e)});var t,r}),h.style.color=u}else o=o.map(v.toFloat);if(t.match(/^bg/))if(v.css(h,"background-position-"+t[2],""),i=v.css(h,"backgroundPosition").split(" ")["x"===t[2]?0:1],g.covers){var l=Math.min.apply(Math,o),d=Math.max.apply(Math,o),f=o.indexOf(l)<o.indexOf(d);a=d-l,o=o.map(function(e){return e-(f?l:d)}),r=(f?-a:0)+"px"}else r=i;return e[t]={steps:o,unit:c,pos:r,bgPos:i,diff:a},e},{})},bgProps:function(){var t=this;return["bgx","bgy"].filter(function(e){return e in t.props})},covers:function(e,t){return i=(r=t).style.backgroundSize,a="cover"===v.css(v.css(r,"backgroundSize",""),"backgroundSize"),r.style.backgroundSize=i,a;var r,i,a}},disconnected:function(){delete this._image},update:{read:function(e){var t=this;if(e.active=this.matchMedia,e.dimEl={width:this.$el.offsetWidth,height:this.$el.offsetHeight},!("image"in e)&&this.covers&&this.bgProps.length){var r=v.css(this.$el,"backgroundImage").replace(/^none|url\(["']?(.+?)["']?\)$/,"$1");if(r){var i=new Image;i.src=r,(e.image=i).naturalWidth||(i.onload=function(){return t.$emit()})}}},write:function(e){var c=this,u=e.dimEl,t=e.image,r=e.active;if(t&&t.naturalWidth)if(r){var l={width:t.naturalWidth,height:t.naturalHeight},d=v.Dimensions.cover(l,u);this.bgProps.forEach(function(e){var t=c.props[e],r=t.diff,i=t.bgPos,a=t.steps,s="bgy"===e?"height":"width",n=d[s]-u[s];if(i.match(/%$|0px/)){if(n<r)u[s]=d[s]+r-n;else if(r<n){var o=parseFloat(i);o&&(c.props[e].steps=a.map(function(e){return e-(n-r)/(100/o)}))}d=v.Dimensions.cover(l,u)}}),v.css(this.$el,{backgroundSize:d.width+"px "+d.height+"px",backgroundRepeat:"no-repeat"})}else v.css(this.$el,{backgroundSize:"",backgroundRepeat:""})},events:["load","resize"]},methods:{reset:function(){var r=this;v.each(this.getCss(0),function(e,t){return v.css(r.$el,t,"")})},getCss:function(h){var g=this.props,b=!1;return Object.keys(g).reduce(function(e,t){var r=g[t],i=r.steps,a=r.unit,s=r.pos,n=k(i,h);switch(t){case"x":case"y":if(b)break;var o=["x","y"].map(function(e){return t===e?v.toFloat(n).toFixed(0)+a:g[e]?k(g[e].steps,h,0)+g[e].unit:0}),c=o[0],u=o[1];b=e.transform+=" translate3d("+c+", "+u+", 0)";break;case"rotate":e.transform+=" rotate("+n+"deg)";break;case"scale":e.transform+=" scale("+n+")";break;case"bgy":case"bgx":e["background-position-"+t[2]]="calc("+s+" + "+(n+a)+")";break;case"color":case"backgroundColor":case"borderColor":var l=m(i,h),d=l[0],f=l[1],p=l[2];e[t]="rgba("+d.map(function(e,t){return e+=p*(f[t]-e),3===t?v.toFloat(e):parseInt(e,10)}).join(",")+")";break;case"blur":e.filter+=" blur("+n+"px)";break;case"hue":e.filter+=" hue-rotate("+n+"deg)";break;case"fopacity":e.filter+=" opacity("+n+"%)";break;case"grayscale":case"invert":case"saturate":case"sepia":e.filter+=" "+t+"("+n+"%)";break;default:e[t]=n}return e},{transform:"",filter:""})}}}],props:{target:String,viewport:Number,easing:Number},data:{target:!1,viewport:1,easing:1},computed:{target:function(e,t){var r=e.target;return r&&v.query(r,t)||t}},update:{read:function(e,t){var r=e.percent,i=e.active;if("scroll"!==t.type&&(r=!1),i){var a,s,n=r;return a=v.scrolledOver(this.target)/(this.viewport||1),s=this.easing,{percent:r=v.clamp(a*(1-(s-s*a))),style:n!==r&&this.getCss(r)}}},write:function(e){var t=e.style;e.active?t&&v.css(this.$el,t):this.reset()},events:["scroll","load","resize"]}};return"undefined"!=typeof window&&window.UIkit&&window.UIkit.component("parallax",r),r});