-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
31 lines (26 loc) · 869 Bytes
/
script.js
File metadata and controls
31 lines (26 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// script.js
// ページが読み込まれたら実行
document.addEventListener("DOMContentLoaded", () => {
// ① 自己紹介ボタン機能
const helloBtn = document.getElementById("helloBtn");
const introArea = document.getElementById("introArea");
if (helloBtn && introArea) {
helloBtn.addEventListener("click", () => {
introArea.textContent = "こんにちは!itstudy31 です。Web 開発を勉強中です!";
});
}
// ② トップに戻るボタン
const topBtn = document.getElementById("topBtn");
if (topBtn) {
window.addEventListener("scroll", () => {
if (window.scrollY > 200) {
topBtn.style.display = "block";
} else {
topBtn.style.display = "none";
}
});
topBtn.addEventListener("click", () => {
window.scrollTo({ top: 0, behavior: "smooth" });
});
}
});