0

So right now I have created an onload function in Javascript.... but it's already late when I found out that I can't use any onLoad javascript function with the app I'm working on :(

<script type="text/javascript">
var sticky = document.querySelector('.sticky');
var origOffsetY = sticky.offsetTop;

function onScroll(e) {
window.scrollY >= origOffsetY ? sticky.classList.add('fixed') :
                              sticky.classList.remove('fixed');
}

document.addEventListener('scroll', onScroll);

</script>

Someone recommended me to use BindListeners but I have no idea how it would work? Any help? I can't use jQuery as well....

Constantin
  • 7,926
  • 12
  • 71
  • 112
  • I'm not sure what your question is, but your problem can probably solved through this: http://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element. – Felix Kling Dec 09 '13 at 06:40
  • If a question is solved, it's not deleted here usually. Just answer with your solution, so that anybody else can benefit from that. – Constantin Dec 09 '13 at 08:38

1 Answers1

0
var sticky = document.querySelector('.sticky');
var origOffsetY = sticky.offsetTop;

function onScroll(e) {
window.scrollY >= origOffsetY ? sticky.classList.add('fixed'):sticky.classList.remove('fixed');
}    

(function() {
  document.addEventListener('scroll', onScroll);
})();

are you using jQuery?