Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="1">1</div> // 10px height
- <div class="2">2</div> // 13px height
- <div class="3">3</div> // 11px height
- … // … height
- var divTops = []; //Start an empty array
- $(document).ready(function(){ //When the DOM loads
- $('div').each(function(e){ //For each div
- var top = $(this).offset().top; //Get its top
- divTops.push(top); //and push that top into the array
- });
- });
- $(window).scroll(function(){ //When the user scrolls
- var scrolled = divTops.indexOf($(window).scrollTop()); //get the index number
- if(scrolled === 0){ // Use the index number to control whatever is there.
- //Do something with the first div
- } else if(scrolled === 1){
- //Do something with the second div
- } else if(scrolled === 2){
- //Do something with the third div
- } else {
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement