I am messing around with some jquery trying to get to grips with it.
I have a ul nav which has a absolute position set but after I scroll the page down by 200 pixels i would like that to switch to position fixed so that the nav always stays on the page.
How would I do this?
below is the example I am working on
http://satbulsara.com/tests/
This is done by adding the position of the element relative to the viewport with the current scroll position. The getBoundingClientRect() method returns a DOMReact object of which the 'top' value could be used to get the position relative to the viewport.
To Move Elements On Page Scroll It Takes Only Three Steps:- scrollTop() > 100) { $("#left_right_div"). animate({marginLeft:'100px'},900); $("#right_left_img"). animate({marginRight:'100px'},900); } if ($(window). scrollTop() > 700) { $("#fade_div").
Thanks to everyone for being so quick to help
this is what i wanted
$(document).ready(function() {
var theLoc = $('ul').position().top;
$(window).scroll(function() {
if(theLoc >= $(window).scrollTop()) {
if($('ul').hasClass('fixed')) {
$('ul').removeClass('fixed');
}
} else {
if(!$('ul').hasClass('fixed')) {
$('ul').addClass('fixed');
}
}
});
});
Thanks!!!!!
I wrote this jQuery plugin to do just that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With