<分区>
如何使导航栏像本网站一样在滚动时变小? 这个真的很顺利。
我知道这可能是用 JQuery 完成的。
最佳答案
这是一个例子。您需要在滚动到特定高度时应用一个类,而在 CSS 中,您必须在添加该类时缩小它。
$(document).scroll(function() {
if ($(document).scrollTop() > 100) {
$('.header').addClass('shrinkIt');
} else {
$('.header').removeClass('shrinkIt');
}
})
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.header {
width: 100%;
background: rgba(255, 255, 255, 0.6);
position: fixed;
top: 0px;
left: 0px;
padding: 50px 100px;
transition: all .3s ease;
font-size: 22px;
}
.header.shrinkIt {
padding: 20px 100px;
font-size: 16px;
}
.content {
background: #2b2b99;
height: 1400px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div class="header">
I will shrink.
</div>
<div class="content">
</div>
</div>
关于jquery - 滚动时导航变小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36421923/
相关文章:
html - 如何去除网站两侧的空白区域?重复背景?调整分区大小?我迷路了
css - Webkit 不再在 Google Chrome 中工作?
javascript - jQuery 中的 .hide() 和 .show() 行为奇怪
javascript - jQuery计算插件: Summing subtotals to create grand total
html - Chrome : can't position one absolute div over another when the parent is fixed