I have several divs, and after scrolling the second div will be "position: fixed" and again after some scrolling it will return to "position: static", but the problem is this:
The 4th div will be the next NOT third (because it has been scrolled while we are on the second div).
How can I show the third div after the second?
Here is the FIDDLE : http://jsfiddle.net/5vzze/2/
HTML:
<div id="container"> <div class="slide" id="d1">1</div> <div class="slide" id="d2">2</div> <div class="slide" id="d3">3</div> <div class="slide" id="d4">4</div> <div class="slide" id="d5">5</div> <div class="slide" id="d6">6</div> <div class="slide" id="d7">7</div> </div>
CSS
#container{ position: relative; } .slide{ min-height: 400px; height: 500px; width: 100%; }
JQuery
$(window).scroll(function(){ var curScrollVal = $(window).scrollTop(); if( curScrollVal > 500 && curScrollVal < 1500){ $('#d2').css({'position': 'fixed', 'top': 0, 'background-color': 'pink'}); } else if( curScrollVal > 1500 ){ $('#d2').css({'position': 'static', 'top': 'auto', 'background-color': 'grey'});
source share