Monday, 20 February 2017

jQuery position DIV fixed at top on scroll add css


<div id="startchange"></div> 


$(document).ready(function(){       
var scroll_start = 0;
var startchange = $('#startchange');
var offset = startchange.offset();
if (startchange.length){
$(document).scroll(function() { 
 scroll_start = $(this).scrollTop();
 if(scroll_start > offset.top) {
 $("#cat-menu").css({position:'fixed',top:'0px'});
  } else {
 $('#cat-menu').css({position:'fixed',top:'46px'});
  }
});
}
});

No comments:

Post a Comment