【发布时间】:2018-07-10 07:53:14
【问题描述】:
我正在做一个项目,jquery/js 为粘性菜单添加/删除类的逻辑存在问题,
示例页面: https://anish.kickpages.com/stickymenu/
尝试非常慢地滚动,您会注意到闪烁。
代码:
$(window).load(function() {
var jsHeight = $('#section_o7kn8h_1531206224').parent().height();
$('#section_o7kn8h_1531206224').parent().css('height', jsHeight);
$('#section_o7kn8h_1531206224').parent().addClass('remove-jump');
$(window).scroll(function(){
if ($(window).scrollTop() >= 100) {
$('#section_o7kn8h_1531206224').parent().css('height', 0);
$('#section_o7kn8h_1531206224').addClass('fixed-header-top');
$('#section_o7kn8h_1531206224').css('background', '');
}
else {
$('#section_o7kn8h_1531206224').parent().css('height', jsHeight);
$('#section_o7kn8h_1531206224').removeClass('fixed-header-top');
$('#section_o7kn8h_1531206224').css('background', '');
}
});
});
【问题讨论】:
-
我通过评论解决了这个问题,$('#section_o7kn8h_1531206224').parent().css('height', 0); $('#section_o7kn8h_1531206224').parent().css('height', jsHeight);第一部分的行。
标签: javascript jquery sticky scrolltop