回答編集履歴
2
要件にそうように変更
test
CHANGED
@@ -4,9 +4,9 @@
|
|
4
4
|
|
5
5
|
const rem2px = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
6
6
|
|
7
|
-
|
7
|
+
const parent_height = element.parentElement.clientHeight;
|
8
8
|
|
9
|
-
|
9
|
+
(element as HTMLElement).style.height = parent_height / rem2px * percent / 100 + "rem";
|
10
10
|
|
11
11
|
}
|
12
12
|
|
@@ -18,6 +18,8 @@
|
|
18
18
|
|
19
19
|
const target = document.getElementById("要素名");
|
20
20
|
|
21
|
+
const parent = document.getElemen
|
22
|
+
|
21
23
|
element_height(target, 70/* % */);
|
22
24
|
|
23
25
|
window.onscoll = element_height(target, 70/* % */);
|
1
remなのにemだった
test
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
const element_height = (element: Element, percent: number) => {
|
4
4
|
|
5
|
-
const rem
|
5
|
+
const rem2px = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
6
6
|
|
7
|
-
(element as HTMLElement).style.height = window.innerHeight / rem
|
7
|
+
(element as HTMLElement).style.height = window.innerHeight / rem2px * percent / 100 + "rem";
|
8
8
|
|
9
9
|
console.log(getComputedStyle(document.documentElement).fontSize);
|
10
10
|
|