[英]jQuery position DIV fixed at top on scroll except homepage
I'm using this js & css to fixed jQuery position DIV at top on scroll: 我正在使用此js和CSS将jQuery位置DIV固定在滚动顶部:
$(window).scroll(function(){
if ($(this).scrollTop() > 135) {
$('#task_flyout').addClass('fixed');
} else {
$('#task_flyout').removeClass('fixed');
}
});
.fixed {
position: fixed;
top: 0;
left: 0;
}
and its working fine for me, but now I want to use this fixed menu on all pages except the homepage, I mean my menu will be fixed on scroll at all pages without the homepage. 它对我来说很好用,但是现在我要在除主页之外的所有页面上使用此固定菜单,我的意思是我的菜单将在没有主页的所有页面上固定为滚动显示。 (again i don't want to fixed my homepage menu but need to fixed on all other pages)
(再次,我不想修复我的主页菜单,但需要修复所有其他页面)
Can somebody help me please?... 有人可以帮我吗?...
You should check if you're on the homepage: 您应该检查自己是否在首页上:
if (location.pathname === "/") {
$('#task_flyout').removeClass('fixed');
} else {
$(window).scroll(function(){
if ($(this).scrollTop() > 135) {
$('#task_flyout').addClass('fixed');
} else {
$('#task_flyout').removeClass('fixed');
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.