Files
postshop-backend/public/web/shella/scripts/module.parallax.min.js
2026-02-03 15:31:29 +05:00

1 line
2.7 KiB
JavaScript

theme.Parallax=function(){function t(){this.load()}t.prototype=$.extend({},t.prototype,{load:function(){$.widget("ui.parallax",{options:{ratio:1.2},params:{},_create:function(){var t=this;if(this.params.start_width=this.element.width(),this.params.start_height=this.element.height(),this.params.start_ratio_height=this.params.start_height/this.params.start_width,this._setOption("ratio",this.element.data("ratio"),!0),this._setOption("height",this.element.data("height"),!0),this._setOption("minHeight",this.element.data("min-height"),!0),this.options.height){var i=this.options.height.split(",");this.options.height={xs:i[4],sm:i[3],md:i[2],lg:i[1],xl:i[0]}}else this.element.css({paddingTop:100*t.params.start_ratio_height+"%"});this.options.minHeight&&this.element.css({minHeight:this.options.minHeight+"px"}),this.$content=this.element.children().first(),this._calculateSize(),this._calculatePosition(),this.element.css({overflow:"hidden",position:"relative"}),this.$content.css({position:"absolute",top:"0",left:"50%",transform:"translateX(-50%)"}),$window.on("theme.resize.parallax",function(){t._calculateSize(),t._calculatePosition()}),$window.on("scroll.parallax",function(){t._calculatePosition()}),this.element.addClass("parallax--init")},_calculateSize:function(){this.params.current_width=this.element.width(),this.options.height&&this.element.css({paddingTop:this.options.height[theme.current.bp]}),this.params.current_height=this.element.height(),this.params.current_scale_width=this.params.current_width*this.options.ratio,this.params.current_scale_height=this.params.current_height*this.options.ratio,this.params.stroke_scroll=this.params.current_height+window.innerHeight,this.params.stroke_content=this.params.current_scale_height-this.params.current_height,this.params.stroke_ratio=this.params.stroke_scroll/this.params.stroke_content,this.$content.width(this.params.current_scale_width)},_calculatePosition:function(){this.params.stroke_current=this.params.stroke_scroll-this.element[0].getBoundingClientRect().bottom,this.params.stroke_current=Math.max(this.params.stroke_current,0),this.params.stroke_current=Math.min(this.params.stroke_current,this.params.stroke_scroll),this.params.current_top=-1*this.params.stroke_content+this.params.stroke_current/this.params.stroke_ratio,this.$content.css({transform:"translate(-50%, "+this.params.current_top+"px)"})},_init:function(){},_setOption:function(t,i){$.Widget.prototype._setOption.apply(this,arguments)},destroy:function(){$window.unbind("theme.resize.parallax scroll.parallax"),$.Widget.prototype.destroy.call(this)}})},init:function(t){t.hasClass("parallax--init")||t.parallax()},destroy:function(t){t.hasClass("parallax--init")&&t.parallax("destroy")}}),theme.Parallax=new t},$(function(){theme.Parallax()});