回答編集履歴
4
調整
test
CHANGED
@@ -133,3 +133,52 @@
|
|
133
133
|
<div id="target">target</div>
|
134
134
|
<div class="dummy"></div>
|
135
135
|
```
|
136
|
+
|
137
|
+
# localStorageでページごとにチェックをする
|
138
|
+
|
139
|
+
// prev.html
|
140
|
+
```javascript
|
141
|
+
<script>
|
142
|
+
const checked=new Set(JSON.parse(localStorage.getItem('checked')??"[]"));
|
143
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
144
|
+
console.log(checked);
|
145
|
+
btn_s.addEventListener('click',()=>{
|
146
|
+
checked.add(location.href);
|
147
|
+
localStorage.setItem('checked',JSON.stringify([...checked]));
|
148
|
+
console.log(checked);
|
149
|
+
});
|
150
|
+
btn_r.addEventListener('click',()=>{
|
151
|
+
checked.delete(location.href);
|
152
|
+
localStorage.setItem('checked',JSON.stringify([...checked]));
|
153
|
+
console.log(checked);
|
154
|
+
});
|
155
|
+
});
|
156
|
+
</script>
|
157
|
+
|
158
|
+
<input type="button" id="btn_s" value="set">
|
159
|
+
<input type="button" id="btn_r" value="remove">
|
160
|
+
<a href="next.html">next.html</a>
|
161
|
+
```
|
162
|
+
// next.html
|
163
|
+
```javascript
|
164
|
+
<script>
|
165
|
+
const checked=new Set(JSON.parse(localStorage.getItem('checked')??"[]"));
|
166
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
167
|
+
console.log(checked);
|
168
|
+
btn_s.addEventListener('click',()=>{
|
169
|
+
checked.add(location.href);
|
170
|
+
localStorage.setItem('checked',JSON.stringify([...checked]));
|
171
|
+
console.log(checked);
|
172
|
+
});
|
173
|
+
btn_r.addEventListener('click',()=>{
|
174
|
+
checked.delete(location.href);
|
175
|
+
localStorage.setItem('checked',JSON.stringify([...checked]));
|
176
|
+
console.log(checked);
|
177
|
+
});
|
178
|
+
});
|
179
|
+
</script>
|
180
|
+
|
181
|
+
<input type="button" id="btn_s" value="set">
|
182
|
+
<input type="button" id="btn_r" value="remove">
|
183
|
+
<a href="prev.html">prev</a>
|
184
|
+
```
|
3
chousei
test
CHANGED
@@ -132,11 +132,4 @@
|
|
132
132
|
<div class="dummy"></div>
|
133
133
|
<div id="target">target</div>
|
134
134
|
<div class="dummy"></div>
|
135
|
-
<script>
|
136
|
-
window.addEventListener('scroll',()=> {
|
137
|
-
});
|
138
|
-
</script>
|
139
|
-
<div class="dummy"></div>
|
140
|
-
<div id="target">target</div>
|
141
|
-
<div class="dummy"></div>
|
142
135
|
```
|
2
追記
test
CHANGED
@@ -78,3 +78,65 @@
|
|
78
78
|
<div id="target">target</div>
|
79
79
|
<div class="dummy"></div>
|
80
80
|
```
|
81
|
+
# targetの75%以上が表示されたらモーダルをだす
|
82
|
+
```javascript
|
83
|
+
<style>
|
84
|
+
.dummy{
|
85
|
+
height:150%;
|
86
|
+
background-Color:gray;
|
87
|
+
}
|
88
|
+
#target{
|
89
|
+
background-Color:red;
|
90
|
+
height:50%;
|
91
|
+
}
|
92
|
+
</style>
|
93
|
+
<script>
|
94
|
+
window.addEventListener('DOMContentLoaded', async()=>{
|
95
|
+
const dlg=document.querySelector('dialog');
|
96
|
+
const img=document.querySelector('dialog img');
|
97
|
+
const imgs=[
|
98
|
+
"https://placehold.jp/00ff00/00000/100x100.png?text=2",
|
99
|
+
"https://placehold.jp/0000ff/00000/100x100.png?text=3",
|
100
|
+
"https://placehold.jp/ffff00/00000/100x100.png?text=4",
|
101
|
+
"https://placehold.jp/00ffff/00000/100x100.png?text=5",
|
102
|
+
];
|
103
|
+
let count=0;
|
104
|
+
img.addEventListener('click',()=>{
|
105
|
+
if(count>=imgs.length){
|
106
|
+
dlg.close();
|
107
|
+
document.body.style.overflowY="auto";
|
108
|
+
return;
|
109
|
+
}
|
110
|
+
img.src=imgs[count];
|
111
|
+
count++;
|
112
|
+
});
|
113
|
+
const onScroll = ()=>{
|
114
|
+
const observer = new IntersectionObserver(changes=>{
|
115
|
+
for (let change of changes) {
|
116
|
+
if(change.intersectionRatio >= 0.75){
|
117
|
+
document.body.style.overflowY="hidden";
|
118
|
+
dlg.showModal();
|
119
|
+
window.removeEventListener('scroll',onScroll);
|
120
|
+
}
|
121
|
+
}
|
122
|
+
});
|
123
|
+
observer.observe(document.querySelector('#target'));
|
124
|
+
};
|
125
|
+
window.addEventListener('scroll',onScroll);
|
126
|
+
});
|
127
|
+
</script>
|
128
|
+
<dialog>
|
129
|
+
<img src="https://placehold.jp/ff0000/00000/100x100.png?text=1"><br>
|
130
|
+
click image!
|
131
|
+
</dialog>
|
132
|
+
<div class="dummy"></div>
|
133
|
+
<div id="target">target</div>
|
134
|
+
<div class="dummy"></div>
|
135
|
+
<script>
|
136
|
+
window.addEventListener('scroll',()=> {
|
137
|
+
});
|
138
|
+
</script>
|
139
|
+
<div class="dummy"></div>
|
140
|
+
<div id="target">target</div>
|
141
|
+
<div class="dummy"></div>
|
142
|
+
```
|
1
調整
test
CHANGED
@@ -24,3 +24,57 @@
|
|
24
24
|
click image!
|
25
25
|
</dialog>
|
26
26
|
```
|
27
|
+
|
28
|
+
# スクロールしてからモーダルを開く
|
29
|
+
```javascript
|
30
|
+
<style>
|
31
|
+
.dummy{
|
32
|
+
height:150%;
|
33
|
+
background-Color:gray;
|
34
|
+
}
|
35
|
+
#target{
|
36
|
+
background-Color:red;
|
37
|
+
}
|
38
|
+
</style>
|
39
|
+
<script>
|
40
|
+
window.addEventListener('DOMContentLoaded', async()=>{
|
41
|
+
const dlg=document.querySelector('dialog');
|
42
|
+
const img=document.querySelector('dialog img');
|
43
|
+
const imgs=[
|
44
|
+
"https://placehold.jp/00ff00/00000/100x100.png?text=2",
|
45
|
+
"https://placehold.jp/0000ff/00000/100x100.png?text=3",
|
46
|
+
"https://placehold.jp/ffff00/00000/100x100.png?text=4",
|
47
|
+
"https://placehold.jp/00ffff/00000/100x100.png?text=5",
|
48
|
+
];
|
49
|
+
let count=0;
|
50
|
+
img.addEventListener('click',()=>{
|
51
|
+
if(count>=imgs.length){
|
52
|
+
dlg.close();
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
img.src=imgs[count];
|
56
|
+
count++;
|
57
|
+
});
|
58
|
+
let timerId;
|
59
|
+
let onScroll = ()=>{
|
60
|
+
clearTimeout(timerId);
|
61
|
+
timerId = setTimeout(()=>{
|
62
|
+
dlg.showModal();
|
63
|
+
window.removeEventListener('scroll',onScroll);
|
64
|
+
},100);
|
65
|
+
};
|
66
|
+
window.addEventListener('scroll',onScroll);
|
67
|
+
window.scrollTo({
|
68
|
+
top: document.body.scrollTop+target.getBoundingClientRect().top,
|
69
|
+
behavior: "smooth",
|
70
|
+
});
|
71
|
+
});
|
72
|
+
</script>
|
73
|
+
<dialog>
|
74
|
+
<img src="https://placehold.jp/ff0000/00000/100x100.png?text=1"><br>
|
75
|
+
click image!
|
76
|
+
</dialog>
|
77
|
+
<div class="dummy"></div>
|
78
|
+
<div id="target">target</div>
|
79
|
+
<div class="dummy"></div>
|
80
|
+
```
|