I have a top fixed div and then a main frame which contains two divs inside (left and right).
I want to make the right div stick just under the top bar on scroll.
I’ve put up what I have here:
http://jsfiddle.net/mhD9Y/2/
$(document).ready(function(){
var window_top = 41 - $(window).scrollTop();
var div_top = $('#stop_scroll').offset().top;
if (window_top > div_top)
$('#right').addClass('stick');
else
$('#right').removeClass('stick');
});
.stick {
position: fixed !important;
top: 41px !important;z-index: 5 !important; -webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
}
The thing is that the script doesn’t kick in at all.
thanks
Put your code with window scroll.
Either you change the id=”right” to class=”right”
OR
Change your css of the
.stick and add !important at the end of each attribute.
DEMO on jsfiddle