UNPKG

ng2-parallaxscroll

Version:

A parallax directive for Angular 2+, now with Universal support!

2 lines 3.12 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/common")):"function"==typeof define&&define.amd?define("ng2-parallaxscroll",["exports","@angular/core","@angular/common"],e):e((t=t||self)["ng2-parallaxscroll"]={},t.ng.core,t.ng.common)}(this,function(t,e,n){"use strict";var l=function(){function t(){}return t.prototype.ngOnInit=function(){this.parallaxStyles={"background-image":this.img?"url("+this.img+")":"",height:"100%",width:"100%"}},t.decorators=[{type:e.Component,args:[{selector:"ng-parallax",template:'\n <div parallax [config]="config"\n [ngStyle]="parallaxStyles"\n [ngClass]="paraClass">\n <ng-content></ng-content>\n </div>\n ',styles:["\n :host {\n display: block;\n }\n "]}]}],t.propDecorators={config:[{type:e.Input}],img:[{type:e.Input,args:["img"]}],paraClass:[{type:e.Input,args:["class"]}]},t}();var s=function(){function t(t,e){var l=this;this.platformId=e,this.axis="Y",this.speed=-.7,this.initialValue=0,this.cssUnit="px",this.parallaxPivot="50%",this.cssProperty="backgroundPosition",this.onScroll=function(){var t,e;e=l.testBrowser&&l.scrollElement instanceof Window?l.scrollElement.scrollY*l.speed+l.initialValue:l.scrollElement.scrollTop*l.speed+l.initialValue,void 0!==l.maxValue&&e>=l.maxValue?e=l.maxValue:void 0!==l.minValue&&e<=l.minValue&&(e=l.minValue),t="X"===l.axis?"calc("+l.parallaxPivot+" + "+e+l.cssUnit+") center":"center calc("+l.parallaxPivot+" + "+e+l.cssUnit+")",l.parallaxElement.style[l.cssProperty]=t},this.hostElement=t.nativeElement,this.testBrowser=n.isPlatformBrowser(this.platformId),this.backupElement=this.testBrowser?window:this.hostElement}return t.prototype.ngOnInit=function(){for(var t in this.config)this.config.hasOwnProperty(t)&&(this[t]=this.config[t]);if(this.speed=+this.speed,this.initialValue=+this.initialValue,this.parallaxElement=this.parallaxElement||this.hostElement,this.scrollerId)try{if(this.scrollElement=document.getElementById(this.scrollerId),!this.scrollElement)throw new Error("ID ('"+this.scrollerId+"') does not exist! Using default")}catch(t){this.scrollElement=this.backupElement}else this.scrollElement=this.backupElement;this.onScroll(),this.scrollElement.addEventListener("scroll",this.onScroll.bind(this))},t.decorators=[{type:e.Directive,args:[{selector:"[parallax]"}]}],t.ctorParameters=function(){return[{type:e.ElementRef},{type:Object,decorators:[{type:e.Inject,args:[e.PLATFORM_ID]}]}]},t.propDecorators={config:[{type:e.Input}],axis:[{type:e.Input}],speed:[{type:e.Input}],initialValue:[{type:e.Input}],maxValue:[{type:e.Input}],minValue:[{type:e.Input}],cssUnit:[{type:e.Input}],scrollerId:[{type:e.Input}],parallaxElement:[{type:e.Input}],parallaxPivot:[{type:e.Input}]},t}();var a=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{declarations:[l,s],imports:[n.CommonModule],exports:[l,s]}]}],t}();t.ParallaxScrollComponent=l,t.ParallaxScrollModule=a,t.ɵa=s,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=ng2-parallaxscroll.umd.min.js.map