3
從頂部標題修復滾動不起作用。滾動標題固定jQuery代碼不起作用
代碼段:
$(document).ready(function() {
$(window).scroll(function() {
if ($(this).scrollTop() > 350) {
$('.header-nav').addClass('fixed2');
} else {
$('.header-nav').removeClass('fixed2');
}
});
});
.fixed2 {
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: cornflowerblue;
}
html {
min-height: 1000px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="header-nav">
<ul id="main-nav">
<li><a href="index.html" class="active">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="#">Register Your Business</a></li>
</ul>
</div>
jQuery代碼不衝突,我用$
jQuery的。
jQuery不工作。
你真的想與滾動這裏做什麼? –
比'_not working _'更具體,你能提供一個解決問題的小工具嗎? –
您是否檢查了控制檯的錯誤? – Pete