Return to Snippet

Revision: 31600
at September 9, 2010 09:48 by Meander365


Initial Code
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');
    }
  });
});

Initial URL
http://jqueryfordesigners.com/fixed-floating-elements/

Initial Description
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*.

Initial Title
Fixed Position of An Element Relevant to Parent

Initial Tags
css, javascript, jquery

Initial Language
JavaScript