I was executing code about window scrollTop where as you scroll up by 200 you have a div with one behaviour and if you cross 500px you would have div behave in another way. The later is not getting executed but just first one is executing. I am starting to learn javascript so please forgive me if this is a small fix :) Here's the code:
window.onscroll = function() {myFunction()};
function myFunction() {
if(document.body.scrollTop > 200 || document.documentElement.scrollTop > 200) {
document.getElementById("meBox").style.position = "fixed";
document.getElementById("meBox").style.background = "green";
} else if (document.body.scrollTop > 500 || document.documentElement.scrollTop > 500) {
document.getElementById("meBox").style.position = "fixed";
document.getElementById("meBox").style.background = "pink";
} else {
document.getElementById("meBox").style.position = "";
document.getElementById("meBox").style.background = "";
}
}//end function
*{margin: 0; padding: 0;}
body {height: 3000px;}
.box {float: left; width: 100%; height: 70px; background: yellow; padding: 15px; box-sizing: border-box; margin: 0; position: relative;}
.box h2 {margin: 0; padding: 0;}
<div class="box" id="meBox"><h2>I am Heading</h2></div>
Please help!
Thanks in advance