2

I'm trying to make my title stick to the top of the window until it's container has scrolled out of view and then stick the next title to the top of the window...

See here for an example https://codepen.io/anon/pen/GWJwRx

I can't seem to figure it out and wondered if anybody could see where i may be going wrong...

$(window).scroll(function(){
  var scroll_top = $(this).scrollTop(); 
  var height_element_parent =  $(".wrapper").height();
  var height_element = $(".menuleft").height(); 
  var position_fixed_max = height_element_parent - height_element; 
  var position_fixed = scroll_top < 100 ? 140 - scroll_top : position_fixed_max > scroll_top ? 40 : position_fixed_max - scroll_top ;
  $(".menuleft").css("top",position_fixed);
});
Liam
  • 9,725
  • 39
  • 111
  • 209
  • http://stackoverflow.com/questions/1216114/how-can-i-make-a-div-stick-to-the-top-of-the-screen-once-its-been-scrolled-to – kaetzacoatl Feb 27 '17 at 18:32
  • `height_element_parent` is always `null`. I think it is because there is no class named `wrapper`. Could you please check it? – Mehmet Baker Feb 27 '17 at 18:35

0 Answers0