Skip to content

Instantly share code, notes, and snippets.

@xuechong87
Created April 22, 2016 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuechong87/0f37f4f6588b889feb639a2f9284fca3 to your computer and use it in GitHub Desktop.
Save xuechong87/0f37f4f6588b889feb639a2f9284fca3 to your computer and use it in GitHub Desktop.
//.recruit-sidebar{position:fixed;display:none;}
$(window,document).on("scroll",function(){
var totalH = $(document).height();//文档总高度
var eleH = 550;//元素高度
var originPadTop = 420;//初始高度
var btmH = 452;//元素在最底部时 元素底部与文档底部高度差
var floationPadTop = 80;//悬浮时顶部高度
function ch(scT){
if(scT<=originPadTop-floationPadTop){
return originPadTop-scT;
}
if((totalH-scT) <= (btmH + eleH + originPadTop)){
return originPadTop -((btmH + eleH + originPadTop)-(totalH-scT));
}
return floationPadTop;
}
var topV = ch($(window).scrollTop());
$(".recruit-sidebar").css({
top:topV
});
});
$(window).scroll();
$(".recruit-sidebar").show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment