HTML
<section id="imag" class = "paral-1 image-contain">
</section>
JAVAScript
var g = 0;
//var myImage = document.getElementById("imag");
window.addEventListener('scroll', pageScrolled);
function pageScrolled() {
g = g + 10;
document.getElementById("imag").style.top = -g+"px" ;
}
- First, the function should be called on scrolling but when page loads it is called.
- Second, When I scroll the function should update the variable "g" with 10 but it is increased by like 100. What is this weird beahviour. You can open console and check. Here's the fiddle - https://jsfiddle.net/LuLt0mh0/