【发布时间】:2015-11-12 12:59:31
【问题描述】:
我正在尝试为引导导航栏设置动画。当页面加载时,您会看到完整大小的徽标,当您向下滚动时,导航栏的大小会减小,并且较小的徽标会淡入。到目前为止,我遇到了一个故障,最终可能导致两个徽标都在视图中如果您向下滚动一点,然后快速向上滚动。因此,我正在寻找一种最佳方式来确保在任何给定时间只有一个徽标。这是我的 jQuery:
var header_closed = false;
var header_open = true;
var timer;
$(window).scroll(function() {
if (timer) {
window.clearTimeout(timer);
}
timer = window.setTimeout(function() {
if ($(document).scrollTop() > 20 && header_closed === false) {
header_closed = true;
header_open = false;
$('.biglogo').fadeOut("fast", function() {
$('.navbar-header').animate({
height: "54px"
}, 250, function() {
$('.smllogo').fadeIn(500);
});
});
} else if ($(document).scrollTop() < 20 && header_open === false) {
header_open = true;
header_closed = false;
$('.smllogo').fadeOut(500, function() {
$('.navbar-header').animate({
height: "138px"
}, 250, function() {
$('.biglogo').fadeIn('fast');
});
});
}
}, 200);
});
html 只是一个普通的引导固定导航栏,有两个导航栏品牌(小标志有一个 display: hidden; 加载时隐藏它..有什么想法吗?
【问题讨论】:
标签: javascript jquery html twitter-bootstrap