Jquery implements a fixed effect when sliding to a certain position

  • 2020-03-30 03:22:35
  • OfStack

 
<script type="text/javascript"> 
$.fn.silde = function() { 
var position = function(element) { 
var top = element.position().top, pos = element.css 
("position"); 
$(window).scroll(function() { 
var scrolls = $(this).scrollTop(); 
if (scrolls > top) { 
if (window.XMLHttpRequest) { 
element.css({ 
position: "fixed", 
top: 0, 
left:1080, 
"margin-left":"0px", 

}); 
} else { 
element.css({ 
top: scrolls, 
"margin-left":"20px" 
}); 
} 
}else { 
element.css({ 
position: pos, 
top: top, 
"margin-left":"20px" 
}); 
} 
}); 
}; 
return $(this).each(function() { 
position($(this)); 

}); 
}; 
$("#ding").silde(); 
</script> 

Related articles: