Hi there, been following the tutorials for smooth parallax scrolling and running into issues in safari. Im targeting a div which is placed absolutely within it’s parent. Any help would be greatly appreciated!! Here is the js snippet which is a mixup of two of Kirupa’s YouTube tutorials…
var xScrollPosition;
var yScrollPosition;
var selectedImage = document.querySelector("#selectedImage");
var requestAnimation = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || window.oRequestAnimationFrame;
function setTranslate(xPos, yPos, el) {
el.style.transform = "translate3d(" + xPos +", " + yPos + "px, 0";
}
function scrollLoop() {
xScrollPosition = window.scrollX;
yScrollPosition = window.scrollY;
setTranslate(0, yScrollPosition * 1.5, selectedImage);
requestAnimation(scrollLoop);
}
window.addEventListener("DOMContentLoaded", scrollLoop, false);