質問編集履歴
2
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
|
16
16
|
<div class="container">
|
17
17
|
<main>
|
18
|
-
<p>コンテンツの高さは
|
18
|
+
<p>コンテンツの高さは5000</p>
|
19
19
|
</main>
|
20
20
|
<footer class="footer">
|
21
21
|
<p>フッター</p>
|
@@ -55,7 +55,7 @@
|
|
55
55
|
opacity: 0;
|
56
56
|
}
|
57
57
|
main {
|
58
|
-
height:
|
58
|
+
height: 5000px;
|
59
59
|
text-align: center;
|
60
60
|
}
|
61
61
|
.footer {
|
1
tuiki
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,4 +4,96 @@
|
|
4
4
|
|
5
5
|
それともこういう誤差は出るものなのでしょうか?
|
6
6
|
|
7
|
-

|
7
|
+

|
8
|
+
|
9
|
+
|
10
|
+
HTML
|
11
|
+
```
|
12
|
+
<div class="page-top">
|
13
|
+
<a href="#" class="page-top_link"></a>
|
14
|
+
</div>
|
15
|
+
|
16
|
+
<div class="container">
|
17
|
+
<main>
|
18
|
+
<p>コンテンツの高さは1200</p>
|
19
|
+
</main>
|
20
|
+
<footer class="footer">
|
21
|
+
<p>フッター</p>
|
22
|
+
</footer>
|
23
|
+
</div>
|
24
|
+
```
|
25
|
+
CSS
|
26
|
+
```
|
27
|
+
.page-top {
|
28
|
+
position: fixed;
|
29
|
+
bottom: 20px;
|
30
|
+
right: 20px;
|
31
|
+
transition: 0.5s;
|
32
|
+
}
|
33
|
+
.page-top_link {
|
34
|
+
position: relative;
|
35
|
+
display: block;
|
36
|
+
width: 45px;
|
37
|
+
height: 45px;
|
38
|
+
border-radius: 10px;
|
39
|
+
background-color: #cccccc;
|
40
|
+
}
|
41
|
+
.page-top_link:before {
|
42
|
+
content: "";
|
43
|
+
display: block;
|
44
|
+
position: absolute;
|
45
|
+
top: 55%;
|
46
|
+
left: 50%;
|
47
|
+
transform: translate(-50%, -50%) rotate(45deg);
|
48
|
+
width: 8px;
|
49
|
+
height: 8px;
|
50
|
+
border-top: 2px solid #fff;
|
51
|
+
border-left: 2px solid #fff;
|
52
|
+
}
|
53
|
+
.is-hidden {
|
54
|
+
visibility: hidden;
|
55
|
+
opacity: 0;
|
56
|
+
}
|
57
|
+
main {
|
58
|
+
height: 1200px;
|
59
|
+
text-align: center;
|
60
|
+
}
|
61
|
+
.footer {
|
62
|
+
height: 100px;
|
63
|
+
background-color: #ff5757;
|
64
|
+
padding: 20px;
|
65
|
+
color: #fff;
|
66
|
+
text-align: center;
|
67
|
+
}
|
68
|
+
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
js
|
73
|
+
```
|
74
|
+
$(function() {
|
75
|
+
|
76
|
+
|
77
|
+
var elem = $(".footer");
|
78
|
+
var banner = $(".page-top");
|
79
|
+
|
80
|
+
var elemO = elem.offset().top; // ページトップからの要素の高さを取得
|
81
|
+
|
82
|
+
var windowH = $(window).height(); // ウィンドウの高さを取得
|
83
|
+
|
84
|
+
$(window).on("scroll", function() { // スクロールした値を取得
|
85
|
+
|
86
|
+
|
87
|
+
var windowS = $(window).scrollTop(); // 現在の位置
|
88
|
+
|
89
|
+
|
90
|
+
if(windowS > elemO - windowH + (windowH / 2) ){ // 要素が見えたら動く
|
91
|
+
banner.addClass("is-hidden");
|
92
|
+
}else{
|
93
|
+
banner.removeClass("is-hidden");
|
94
|
+
}
|
95
|
+
|
96
|
+
});
|
97
|
+
|
98
|
+
});
|
99
|
+
```
|