【发布时间】:2020-06-05 06:10:12
【问题描述】:
我不太擅长 JavaScript 或 jQuery。我有两段不同的代码,但后者似乎与第一段冲突。
我的第一个代码是为滚动导航添加背景颜色:
jQuery(function () {
jQuery(document).ready(function(){
jQuery(window).on("scroll",function(){
if(jQuery(document).scrollTop() > 200)
jQuery(".header").css({backgroundColor:"#4A6971"});
else
jQuery(".header").css({backgroundColor:"transparent"});
})
})
});
我的第二个代码是触发我从 animate.css 获得的动画淡入:
jQuery(function () {
jQuery(window).scroll(function () {
console.log(jQuery(window).scrollTop());
var topDivHeight = jQuery(".showcase_div").height();
var viewPortSize = jQuery(window).height();
var triggerAt = 150;
var triggerHeight = (topDivHeight - viewPortSize) + triggerAt;
if (jQuery(window).scrollTop() >= triggerHeight) {
jQuery('.pic1').css('visibility', 'visible').hide().fadeIn();
jQuery(this).off('scroll');
}
});
});
为什么第二个代码与第一个代码冲突?自从我添加了第二个代码后,导航上的背景颜色不再出现。
谁能帮忙?
【问题讨论】:
-
请提供一个有效的sn-p。所以我们可以看到 HTML/CSS 和动作,更好地理解发生了什么。
-
你应该在做第二个滚动分配之前取消绑定滚动事件。
标签: javascript jquery