0

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

RobC
  • 45
  • 8

1 Answers1

2

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

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
  • won't work. you have to wait for scrolltop to do its stuff and that takes and results in jerky repositioning allbeit fairly rapid. That is why I put easing in, to take out the jerkiness. – RobC Feb 08 '13 at 05:27
  • @RobC you could prevent the default scrolling and then scroll the window and the div together manually – Explosion Pills Feb 08 '13 at 05:34
  • don't think that would work, Docs say scroll event is fired when content position is changed so its too late. I think some other event needs to be trapped but don't know which or if its even possible. – RobC Feb 08 '13 at 05:52
  • @RobC maybe this will help: http://stackoverflow.com/questions/4770025/how-to-disable-scrolling-temporarily – Explosion Pills Feb 08 '13 at 05:54
  • having thought about this some more, I think that scroll must happen for there to be a new scrollTop value to use to reposition the sidemenu. Therefore its impossible to do using the scroll event disabled. I think I'll have to take the sidemenu out of the scroll area to get it to remain static whilst scrolling. – RobC Feb 08 '13 at 06:12