RobC
RobC

Reputation: 45

when scrolling how to keep a div fixed without using position:fixed

I have just created a sidemenu which doesn't scroll with the rest of the page, or rather it repositions itself to top of containing div by using the scroll event, taking the scrollTop value and repostioning the sidemenu div using a tad of easing. This all works fine but I would rather it just remained static without moving at all. So question is, is there a way to make it remain absolutely static WITHOUT using position:fixed? (position:fixed causes other problems with window resizing which need hacks to solve. Using absolute also causes same problems)

my code currently:

$('#mainbox').scroll(function() {
  var newTopMargin = $(this).scrollTop();
  $('#sidemenu').animate({marginTop: newTopMargin}, 100 );
});     

thanks

Upvotes: 0

Views: 767

Answers (1)

Explosion Pills
Explosion Pills

Reputation: 191749

Don't use .animate. Just use .css('marginTop', newTopMargin). I guess you could also just remove the 100 from .animate

Upvotes: 2

Related Questions