| Server IP : 14.225.204.176 / Your IP : 216.73.216.252 Web Server : nginx/1.24.0 System : Linux nodejs-ybgk 6.8.0-40-generic #40-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 5 10:34:03 UTC 2024 x86_64 User : root ( 0) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/php/zinisoft.net-react/node_modules/jarallax/src/ |
Upload File : |
/* eslint no-case-declarations: "off" */
import global from 'global';
export default function jarallaxElement( jarallax = global.jarallax ) {
if ( 'undefined' === typeof jarallax ) {
return;
}
const Jarallax = jarallax.constructor;
// redefine default methods
[
'initImg',
'canInitParallax',
'init',
'destroy',
'clipContainer',
'coverImage',
'isVisible',
'onScroll',
'onResize',
].forEach( ( key ) => {
const def = Jarallax.prototype[ key ];
Jarallax.prototype[ key ] = function( ...args ) {
const self = this;
if ( 'initImg' === key && null !== self.$item.getAttribute( 'data-jarallax-element' ) ) {
self.options.type = 'element';
self.pureOptions.speed = self.$item.getAttribute( 'data-jarallax-element' ) || self.pureOptions.speed;
}
if ( 'element' !== self.options.type ) {
return def.apply( self, args );
}
self.pureOptions.threshold = self.$item.getAttribute( 'data-threshold' ) || '';
switch ( key ) {
case 'init':
const speedArr = self.pureOptions.speed.split( ' ' );
self.options.speed = self.pureOptions.speed || 0;
self.options.speedY = speedArr[ 0 ] ? parseFloat( speedArr[ 0 ] ) : 0;
self.options.speedX = speedArr[ 1 ] ? parseFloat( speedArr[ 1 ] ) : 0;
const thresholdArr = self.pureOptions.threshold.split( ' ' );
self.options.thresholdY = thresholdArr[ 0 ] ? parseFloat( thresholdArr[ 0 ] ) : null;
self.options.thresholdX = thresholdArr[ 1 ] ? parseFloat( thresholdArr[ 1 ] ) : null;
def.apply( self, args );
// restore background image if available.
const originalStylesTag = self.$item.getAttribute( 'data-jarallax-original-styles' );
if ( originalStylesTag ) {
self.$item.setAttribute( 'style', originalStylesTag );
}
return true;
case 'onResize':
const defTransform = self.css( self.$item, 'transform' );
self.css( self.$item, { transform: '' } );
const rect = self.$item.getBoundingClientRect();
self.itemData = {
width: rect.width,
height: rect.height,
y: rect.top + self.getWindowData().y,
x: rect.left,
};
self.css( self.$item, { transform: defTransform } );
break;
case 'onScroll':
const wnd = self.getWindowData();
const centerPercent = ( wnd.y + wnd.height / 2 - self.itemData.y - self.itemData.height / 2 ) / ( wnd.height / 2 );
const moveY = centerPercent * self.options.speedY;
const moveX = centerPercent * self.options.speedX;
let my = moveY;
let mx = moveX;
if ( null !== self.options.thresholdY && moveY > self.options.thresholdY ) my = 0;
if ( null !== self.options.thresholdX && moveX > self.options.thresholdX ) mx = 0;
self.css( self.$item, { transform: `translate3d(${ mx }px,${ my }px,0)` } );
break;
case 'initImg':
case 'isVisible':
case 'clipContainer':
case 'coverImage':
return true;
// no default
}
return def.apply( self, args );
};
} );
}