自學網頁前端

2022/03/02閱讀時間約 1 分鐘
教到了JS event,非常實用的一堂課程,開始進入監聽階段,可以跟使用者互動,也慢慢建立UX的概念,讓我可以開始自行設計動態網頁,並且優化了第二個靜態網頁,加入了滾動變化的效果。
let header = document.querySelector("header");
let headerAnchor = document.querySelectorAll("header nav ul li a")
window.addEventListener("scroll",() => {
if (window.pageYOffset != 0){
header.style.backgroundColor ="rgba(72,60,139,0.3";
header.style.color = "white";
headerAnchor.forEach(a => {
a.style.color = "white";
})
} else{
header.style.backgroundColor = "";
header.style.color = "";
headerAnchor.forEach(a => {
a.style.color = "#381b11";
})
}
})
黎羊Leon
黎羊Leon
留言0
查看全部
發表第一個留言支持創作者!