@ngu/parallax
Version:
Angular universal parallax
1 lines • 2.57 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/platform-browser")):"function"==typeof define&&define.amd?define(["exports","@angular/core","@angular/platform-browser"],e):e((t.ng=t.ng||{},t.ng.nguparallax=t.ng.nguparallax||{}),t.ng.core,t.ng["platform-browser"])}(this,function(t,e,i){"use strict";var n=function(){function t(t,e,i){this.renderer=t,this.el=e,this.sanitizer=i}return t.prototype.ngOnInit=function(){var t=this;this.img=this.img1.nativeElement,this.parallaxHeight=this.el.nativeElement.offsetHeight,this.renderer.listenGlobal("window","scroll",function(){return t.onWindowScrolling()}),this.windowHeight=window.innerHeight,this._imgSafe=this.sanitizer.bypassSecurityTrustUrl(this.imagedata||"")},Object.defineProperty(t.prototype,"image",{get:function(){return this._imgSafe},enumerable:!0,configurable:!0}),t.prototype.isLoaded=function(t){this.imageHeight=this.img.offsetHeight,this.parallaxOffestTop=this.el.nativeElement.offsetTop,this.imgheit=Math.round((this.imageHeight-this.parallaxHeight)/this.imageHeight*100),this.imgToBeScroll=Math.round(this.parallaxHeight/this.imageHeight*100)},t.prototype.onWindowScrolling=function(){var t=window.scrollY;if(this.parallaxOffestTop<=t+this.windowHeight&&this.parallaxOffestTop+this.parallaxHeight>=t){var e=t-(this.parallaxOffestTop>this.windowHeight?this.parallaxOffestTop-this.windowHeight:0),i=Math.round(e/(this.windowHeight+this.parallaxHeight)*100),n=Math.round(i/100*this.imgToBeScroll);this.renderer.setElementStyle(this.img,"transform","translate3d(0, -"+n+"%, 0)")}},t.decorators=[{type:e.Component,args:[{selector:"ngu-parallax",template:'<img #img [src]="image" (load)="isLoaded($event)"><div><ng-content></ng-content></div>',styles:["\n :host {\n display: block;\n overflow: hidden;\n position: relative;\n }\n\n img {\n width: 100%;\n position: absolute;\n top: 0px;\n left: 0px;\n }\n\n div {\n z-index: 1;\n position: absolute;\n top: 0px;\n left: 0px;\n }\n "]}]}],t.ctorParameters=function(){return[{type:e.Renderer},{type:e.ElementRef},{type:i.DomSanitizer}]},t.propDecorators={imagedata:[{type:e.Input,args:["image"]}],img1:[{type:e.ViewChild,args:["img",{read:e.ElementRef}]}]},t}(),r=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{imports:[],exports:[n],declarations:[n]}]}],t.ctorParameters=function(){return[]},t}();t.NguParallaxModule=r,Object.defineProperty(t,"__esModule",{value:!0})});