jQuery 位置 DIV 固定在除主页外的滚动顶部
jQuery position DIV fixed at top on scroll except homepage
我正在使用此 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;
}
它对我来说工作正常,但现在我想在除主页以外的所有页面上使用这个固定菜单,我的意思是我的菜单将在没有主页的所有页面上固定滚动。 (同样,我不想修复我的主页菜单,但需要修复所有其他页面)
有人可以帮我吗?...
你应该检查一下你是否在主页上:
if (location.pathname === "/") {
$('#task_flyout').removeClass('fixed');
} else {
$(window).scroll(function(){
if ($(this).scrollTop() > 135) {
$('#task_flyout').addClass('fixed');
} else {
$('#task_flyout').removeClass('fixed');
}
});
}
我正在使用此 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;
}
它对我来说工作正常,但现在我想在除主页以外的所有页面上使用这个固定菜单,我的意思是我的菜单将在没有主页的所有页面上固定滚动。 (同样,我不想修复我的主页菜单,但需要修复所有其他页面)
有人可以帮我吗?...
你应该检查一下你是否在主页上:
if (location.pathname === "/") {
$('#task_flyout').removeClass('fixed');
} else {
$(window).scroll(function(){
if ($(this).scrollTop() > 135) {
$('#task_flyout').addClass('fixed');
} else {
$('#task_flyout').removeClass('fixed');
}
});
}