Advertisement
Guest User

Untitled

a guest
Apr 25th, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. <div class="1">1</div> // 10px height
  2. <div class="2">2</div> // 13px height
  3. <div class="3">3</div> // 11px height
  4. … // … height
  5.  
  6. var divTops = []; //Start an empty array
  7. $(document).ready(function(){ //When the DOM loads
  8. $('div').each(function(e){ //For each div
  9. var top = $(this).offset().top; //Get its top
  10. divTops.push(top); //and push that top into the array
  11. });
  12. });
  13.  
  14. $(window).scroll(function(){ //When the user scrolls
  15. var scrolled = divTops.indexOf($(window).scrollTop()); //get the index number
  16. if(scrolled === 0){ // Use the index number to control whatever is there.
  17. //Do something with the first div
  18. } else if(scrolled === 1){
  19. //Do something with the second div
  20. } else if(scrolled === 2){
  21. //Do something with the third div
  22. } else {
  23.  
  24. }
  25. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement