<分区>
我只想在向下滚动时隐藏一张图片并显示另一张图片。当滚动到页面顶部时,第一张图片需要显示,其他图片需要隐藏。
我试过这段代码。
//This is the image I just want to show at first
<img src="images/logo-wh.png" alt="" class="logo-white">
//This is the image I just want to show when scroll down
<img src="images/logo.png" alt="" class="logo-default">
.logo-default{
display:none;
}
$(window).scroll(function() {
if ($(this).scrollTop() > 0) {
$('.logo-white').hide();
} else {
$('.logo-default').show();
}
});
但它并没有像我预期的那样工作。有什么建议么?