I cannot seem to add a transform to the body element (having a mega brain block as to why its not working). I am trying to experiment with some scrolling effects.
Progress thus far:
document.addEventListener('scroll', function () {
var previousScrollPos = 0;
var currentScrollPos = document.body.scrollTop;
var transformValue = -500px;
if(currentScrollPos > previousScrollPos) {
document.body.style.transform = "translate-y(transformValue)";
}
}
UPDATE This is now my working code
document.addEventListener('scroll', scroller)
function scroller() {
var previousScrollPos = 0;
var currentScrollPos = document.body.scrollTop;
var nextScrollPos = 0;
if (currentScrollPos > previousScrollPos) {
nextScrollPos = nextScrollPos - 100;
document.body.style.transform = "translateY(" + nextScrollPos + "vh)";
} else {
nextScrollPos = nextScrollPos + 100;
document.body.style.transform = "translateY(" + previousScrollPos + "vh)";
}
}
-500pxresults inUncaught SyntaxError: Invalid or unexpected token.pxis not a built-in single or set of characters that can be appended to JavaScript primitive number or decimals without resulting in a syntax error. Istransitionproperty set at CSS?"translate-y(transformValue)"does not work this way?-500pxis a string. You can't store it like an integer as you're doing here. Put quotes around it. And when calling the variable, concetenate it like"sting "+ transformValue +" string".