Currently, I am faced with the following dilemma:
I possess an object along with its initial position;
Upon the initiation of page scrolling, my goal is to have this object move downwards towards the center. Once the scroll reaches 100vh (referred to as 'sectionHeight' in the provided example), the objective is for the object to be positioned perfectly at the screen's center and expand by 1.49 times its original size.
The challenge lies in the mathematical aspect as I am struggling to devise a suitable method for calculating the object's trajectory. Thus far, the code snippet I have developed for adjusting the position consists of somewhat arbitrary values in an attempt to achieve the desired outcome:
if(window.pageYOffset < sectionHeight && window.pageYOffset > 0) {
productToExpand.style.position = 'absolute';
productToExpand.style.top = productToExpandPosition.top + window.pageYOffset + 'px';
productToExpand.style.left = productToExpandPosition.left + window.pageYOffset / 2 + 'px';
} else if(window.pageYOffset === 0) {
productToExpand.style.position = 'unset';
} else if (window.pageYOffset > sectionHeight) {
productToExpand.style.top = 1.5 * sectionHeight - productImageToExpand.offsetHeight / 2 + 'px';
productToExpand.style.left = 'calc(50% -' + ' ' + (productImageToExpand.offsetWidth / 2 + productToExpandPositionLeft) + 'px)';
}
Furthermore, determining the appropriate formula for resizing the object poses another challenge. Any assistance in addressing these issues would be greatly appreciated.