window.onload = function(){ var tabTop = $("#tab_demo .tabBar").offset().top; $(".Hui-article").scroll(function(){ var currentTop = $(this).scrollTop()+94; console.log(currentTop+":"+tabTop); if(currentTop >= tabTop){ var topVal = currentTop - tabTop; $("#tab_demo .tabBar").css({ "position":"relative", "top":topVal+"px", "left":"0", "z-index":"11111", "width":"100%", "background":"#fff" }); }else{ $("#tab_demo .tabBar").css({ "position":"static" }); } }); }
实现滚动条超过一定距离, 导航栏悬浮在最上方的功能。
时间: 2024-10-26 10:29:45