| Server IP : 14.225.204.176 / Your IP : 216.73.216.6 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/aos/src/js/helpers/ |
Upload File : |
/**
* Calculate offset
* basing on element's settings like:
* - anchor
* - offset
*
* @param {Node} el [Dom element]
* @return {Integer} [Final offset that will be used to trigger animation in good position]
*/
import getOffset from './../libs/offset';
const calculateOffset = function (el, optionalOffset) {
let elementOffsetTop = 0;
let additionalOffset = 0;
const windowHeight = window.innerHeight;
const attrs = {
offset: el.getAttribute('data-aos-offset'),
anchor: el.getAttribute('data-aos-anchor'),
anchorPlacement: el.getAttribute('data-aos-anchor-placement')
};
if (attrs.offset && !isNaN(attrs.offset)) {
additionalOffset = parseInt(attrs.offset);
}
if (attrs.anchor && document.querySelectorAll(attrs.anchor)) {
el = document.querySelectorAll(attrs.anchor)[0];
}
elementOffsetTop = getOffset(el).top;
switch (attrs.anchorPlacement) {
case 'top-bottom':
// Default offset
break;
case 'center-bottom':
elementOffsetTop += el.offsetHeight / 2;
break;
case 'bottom-bottom':
elementOffsetTop += el.offsetHeight;
break;
case 'top-center':
elementOffsetTop += windowHeight / 2;
break;
case 'bottom-center':
elementOffsetTop += windowHeight / 2 + el.offsetHeight;
break;
case 'center-center':
elementOffsetTop += windowHeight / 2 + el.offsetHeight / 2;
break;
case 'top-top':
elementOffsetTop += windowHeight;
break;
case 'bottom-top':
elementOffsetTop += el.offsetHeight + windowHeight;
break;
case 'center-top':
elementOffsetTop += el.offsetHeight / 2 + windowHeight;
break;
}
if (!attrs.anchorPlacement && !attrs.offset && !isNaN(optionalOffset)) {
additionalOffset = optionalOffset;
}
return elementOffsetTop + additionalOffset;
};
export default calculateOffset;