/ Published in: JavaScript

Great for those situations where you need an element fixed on a page - so when a user scrolls it stays in the same position - *relative to its parent element*.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var top = $('#tabs').offset().top - parseFloat($('#tabs').css('marginTop').replace(/auto/, 0)); $(window).scroll(function (event) { // what the y position of the scroll is var y = $(this).scrollTop(); // whether that's below the form if (y >= top) { // if so, ad the fixed class $('#tabs').addClass('fixed'); } else { // otherwise remove it $('#tabs').removeClass('fixed'); } }); });
URL: http://jqueryfordesigners.com/fixed-floating-elements/
Comments
