Skip to content

Commit b7f7c0b

Browse files
author
y-yamasaki
committed
p5.js調整
1 parent 23ae8e0 commit b7f7c0b

2 files changed

Lines changed: 29 additions & 28 deletions

File tree

assets/css/base.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ html {
5959
scroll-behavior: smooth;
6060
-webkit-text-size-adjust: 100%;
6161
text-size-adjust: 100%;
62+
overflow-x: hidden; /* 横スクロール防止 */
6263
}
6364

6465
body {
6566
margin: 0;
6667
padding: 0;
67-
overflow-x: hidden;
68+
overflow-x: hidden; /* 横スクロール防止 */
6869
font-family: var(--font-body);
6970
line-height: 1.6;
7071
color: var(--color-text);
@@ -88,6 +89,8 @@ body {
8889
min-height: 100vh;
8990
display: flex;
9091
flex-direction: column;
92+
overflow-wrap: break-word; /* 長い単語の折り返し */
93+
word-break: break-word; /* 長い単語の折り返し(互換性) */
9194
}
9295

9396
h1,
@@ -197,6 +200,7 @@ button {
197200
margin: 0 auto;
198201
padding: 2.5rem 1.25rem;
199202
flex-grow: 1;
203+
width: 100%; /* コンテナのはみ出し防止 */
200204
}
201205

202206
.text-muted {

assets/js/menuAnimation.js

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,16 @@ const repulsionStrength = 20;
1010
let isMouseInsideBrowserWindow = false;
1111

1212
function setup() {
13-
// ページの全体の高さを取得
14-
let pageHeight = Math.max(
15-
document.body.scrollHeight,
16-
document.documentElement.scrollHeight,
17-
document.body.offsetHeight,
18-
document.documentElement.offsetHeight,
19-
document.body.clientHeight,
20-
document.documentElement.clientHeight,
21-
);
13+
// スクロールバーを含まないビューポートの幅を取得
14+
let w = document.documentElement.clientWidth;
15+
// 背景固定 (fixed) なので、ページ全体の高さではなくウィンドウの高さを使用
16+
let h = windowHeight;
2217

23-
animationCanvas = createCanvas(windowWidth, pageHeight);
18+
animationCanvas = createCanvas(w, h);
2419
animationCanvas.position(0, 0);
20+
21+
// position: fixed を明示的に設定(p5.jsのデフォルト動作による上書き防止)
22+
animationCanvas.style("position", "fixed");
2523
animationCanvas.style("z-index", "-1");
2624
animationCanvas.style("pointer-events", "none");
2725

@@ -40,15 +38,10 @@ function draw() {
4038
}
4139

4240
function windowResized() {
43-
let pageHeight = Math.max(
44-
document.body.scrollHeight,
45-
document.documentElement.scrollHeight,
46-
document.body.offsetHeight,
47-
document.documentElement.offsetHeight,
48-
document.body.clientHeight,
49-
document.documentElement.clientHeight,
50-
);
51-
resizeCanvas(windowWidth, pageHeight);
41+
// リサイズ時もスクロールバーを含まない幅で計算
42+
let w = document.documentElement.clientWidth;
43+
let h = windowHeight;
44+
resizeCanvas(w, h);
5245
}
5346

5447
class Particle {
@@ -88,25 +81,29 @@ class Particle {
8881
this.pos.add(this.vel);
8982
this.acc.mult(0);
9083

84+
// 画面端の判定と位置補正
85+
// (ウィンドウリサイズでキャンバスが小さくなった場合にパーティクルが外に残らないよう constrain で補正)
9186
if (
9287
this.pos.x > width - this.size / 2 ||
9388
this.pos.x < this.size / 2
9489
) {
9590
this.vel.x *= -1;
96-
if (this.pos.x > width - this.size / 2)
97-
this.pos.x = width - this.size / 2;
98-
if (this.pos.x < this.size / 2)
99-
this.pos.x = this.size / 2;
91+
this.pos.x = constrain(
92+
this.pos.x,
93+
this.size / 2,
94+
width - this.size / 2,
95+
);
10096
}
10197
if (
10298
this.pos.y > height - this.size / 2 ||
10399
this.pos.y < this.size / 2
104100
) {
105101
this.vel.y *= -1;
106-
if (this.pos.y > height - this.size / 2)
107-
this.pos.y = height - this.size / 2;
108-
if (this.pos.y < this.size / 2)
109-
this.pos.y = this.size / 2;
102+
this.pos.y = constrain(
103+
this.pos.y,
104+
this.size / 2,
105+
height - this.size / 2,
106+
);
110107
}
111108
}
112109

0 commit comments

Comments
 (0)