在我正在創建的網站中,我希望將一個標題更改爲滾動大小。我已經完成了理論上應用的兩種方法。這個頭文件是包含JS的大文檔的一部分,當我測試其他JS正在工作時,所以我不相信這是一個主要的語法錯誤。另外當我檢查它時,我沒有看到控制檯中的任何錯誤。Scroll上的標題更改
$(document).on('scroll', function(e) {
var value = $(this).scrollTop();
if (value < 100)
$("header").css("height", "100px");
else
$("header").css("height", "45px");
});
header {
height: 300px;
background-color: #69D2E7;
font-family: 'Raleway', sans-serif;
z-index: 30;
width: 100vw;
box-shadow: 1px 1px 10px rgba(40, 40, 40, 0.6);
position: fixed;
}
<header>
<a href="index.html">
<h1>MEH Web Design</h1>
</a>
</header>
$(function() {
var header = $(".hlarge");
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= 200) {
header.removeClass('hlarge').addClass("hsmall");
} else {
header.removeClass("hsmall").addClass('hlarge');
}
});
});
.hlarge {
height: 300px;
background-color: #69D2E7;
font-family: 'Raleway', sans-serif;
z-index: 30;
width: 100vw;
box-shadow: 1px 1px 10px rgba(40, 40, 40, 0.6);
position: fixed;
}
.hsmall {
height: 150px;
background-color: #69D2E7;
font-family: 'Raleway', sans-serif;
z-index: 30;
width: 100vw;
box-shadow: 1px 1px 10px rgba(40, 40, 40, 0.6);
position: fixed;
}
<header class="hlarge">
<a href="index.html">
<h1>MEH Web Design</h1>
</a>
</header>