我喜欢这个网站标签的想法: http://www.usatoday.com/
在 Logo 下方滚动时, 1- 选项卡得到修复。 2- 较小的 Logo 进入选项卡。
或者,您可以说类似于 Google 加标签的东西。 我怎样才能做到这一点.. * 我是数据库开发人员,只有网络技术背景。
感谢您的帮助。 问候,
最佳答案
在桌面上这应该不难:
var navigationIsFixed = false;
var $navigation = $("#navigation");
var headerHeight = $("#my-header").height() //To find the height of the header element
$("body").on('scroll', function(e)) { //Fires continuously while the user scrolls
if ($("body").scrollTop >= headerHeight && !navigationIsFixed) {
$navigation.css({
position: "fixed",
left: 0,
right: 0,
top: 0
});
$("#logo").stop(); //Make sure to stop any possible ongoing animations
$("#logo").doCoolAnimation();
navigationIsFixed = true;
} else if (navigationIsFixed) {
$navigation.css( {position: "static"} );
$("#logo").stop();
$("#logo").doCoolRevertAnimation();
navigationIsFixed = false;
}
}
在移动设备上,它要难一点。您必须将 header 与两个不同 div 中的其余内容分开,因为正文不会像人们想象的那样响应滚动事件。
使用这种方法时,您需要将滚动事件绑定(bind)到内容 div
<div id="header">
//Your header code, including the navigation
</div>
<div id="main-content-wrapper">
//Everything else
</div>
CSS:
#main-content-wrapper {
overflow-y: scroll;
-webkit-overflow-scrolling: touch; //Enables inertia scroll on webkit mobile browsers
}
希望我能帮到你 :)
关于jquery - 使标签位置在滚动时固定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19454426/