-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy03_backToTop.html
More file actions
144 lines (128 loc) · 7.53 KB
/
my03_backToTop.html
File metadata and controls
144 lines (128 loc) · 7.53 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JavaScript for Web Designers - Back to top button demo</title>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Cormorant+Infant:700,700italic|Lato:400,400italic,700"
/>
<link rel="stylesheet" href="my03_backToTop.css" />
</head>
<body>
<!-- https://codepen.io/alikerock/pens -->
<header id="top">
<h1>Moby Dick</h1>
<h2>by Herman Melville</h2>
</header>
<main>
<p>
Presently a breeze sprang up; Stubb feigned to cast off from the whale; hoisting his boats, the
Frenchman soon increased his distance, while the Pequod slid in between him and Stubb's whale. Whereupon
Stubb quickly pulled to the floating body, and hailing the Pequod to give notice of his intentions, at
once proceeded to reap the fruit of his unrighteous cunning. Seizing his sharp boat-spade, he commenced
an excavation in the body, a little behind the side fin. You would almost have thought he was digging a
cellar there in the sea; and when at length his spade struck against the gaunt ribs, it was like turning
up old Roman tiles and pottery buried in fat English loam. His boat's crew were all in high excitement,
eagerly helping their chief, and looking as anxious as gold-hunters.
</p>
<p>
And all the time numberless fowls were diving, and ducking, and screaming, and yelling, and fighting
around them. Stubb was beginning to look disappointed, especially as the horrible nosegay increased,
when suddenly from out the very heart of this plague, there stole a faint stream of perfume, which
flowed through the tide of bad smells without being absorbed by it, as one river will flow into and then
along with another, without at all blending with it for a time.
</p>
<p>
"I have it, I have it," cried Stubb, with delight, striking something in the subterranean regions, "a
purse! a purse!"
</p>
<p>
Dropping his spade, he thrust both hands in, and drew out handfuls of something that looked like ripe
Windsor soap, or rich mottled old cheese; very unctuous and savory withal. You might easily dent it with
your thumb; it is of a hue between yellow and ash colour. And this, good friends, is ambergris, worth a
gold guinea an ounce to any druggist. Some six handfuls were obtained; but more was unavoidably lost in
the sea, and still more, perhaps, might have been secured were it not for impatient Ahab's loud command
to Stubb to desist, and come on board, else the ship would bid them good bye.
</p>
<p>
Now this ambergris is a very curious substance, and so important as an article of commerce, that in 1791
a certain Nantucket-born Captain Coffin was examined at the bar of the English House of Commons on that
subject. For at that time, and indeed until a comparatively late day, the precise origin of ambergris
remained, like amber itself, a problem to the learned. Though the word ambergris is but the French
compound for grey amber, yet the two substances are quite distinct. For amber, though at times found on
the sea-coast, is also dug up in some far inland soils, whereas ambergris is never found except upon the
sea. Besides, amber is a hard, transparent, brittle, odorless substance, used for mouth-pieces to pipes,
for beads and ornaments; but ambergris is soft, waxy, and so highly fragrant and spicy, that it is
largely used in perfumery, in pastiles, precious candles, hair-powders, and pomatum. The Turks use it in
cooking, and also carry it to Mecca, for the same purpose that frankincense is carried to St. Peter's in
Rome. Some wine merchants drop a few grains into claret, to flavor it.
</p>
<p>
Who would think, then, that such fine ladies and gentlemen should regale themselves with an essence
found in the inglorious bowels of a sick whale! Yet so it is. By some, ambergris is supposed to be the
cause, and by others the effect, of the dyspepsia in the whale. How to cure such a dyspepsia it were
hard to say, unless by administering three or four boat loads of Brandreth's pills, and then running out
of harm's way, as laborers do in blasting rocks.
</p>
</main>
<footer>
<p>
<small>
<em
>Typography and color scheme based on
<a href="http://typespiration.com/design/the-signal/">"The Signal"</a>.</em
>
</small>
</p>
<a id="back-to-top" href="#">Top</a>
</footer>
<script>
/*
* - 변수 지정하기
* - 문서의 높이를 계산하고 원하는 부분이 상단에서 얼마큼 떨어져 있는지 offset 값을 계산하기
* - 스크롤과 클릭 이벤트 작성하기
*/
// 변수
var btt = document.getElementById('back-to-top'),
docElem = document.documentElement, //문서 자체
offset, //btn이 보이게 될 높이
scrollPos,
docHeight;
// 문서 높이 계산하기 - 브라우저마다 문서 높이가 다를 수도 있음.
// docHeight = docElem.scrollHeight; //문서 자체의 높이
//docHeight = docElem.offsetHeight; //문서 자체의 높이
// console.log(docHeight);
docHeight = Math.max(docElem.offsetHeight, docElem.scrollHeight); // 문서의 높이
// console.log(scrollPos);
if (docHeight != 0) {
offset = docHeight / 4;
}
// 스크롤 이벤트 추가
window.addEventListener('scroll', function () {
scrollPos = docElem.scrollTop; // 스크롤이 얼만큼 생기는지..
// console.log(scrollPos);
btt.className = scrollPos > offset ? 'visible' : '';
});
// 클릭 이벤트 추가
btt.addEventListener('click', function (e) {
e.preventDefault(); // button이 가지고 있는 링크의 기능을 막는다
// docElem.scrollTop = 0;
scrollToTop();
});
// 일정 시간 마다 스크롤양을 조금씩 빼다가, 0이 되면 멈춘다.
function scrollToTop() {
// scroll양이 0보다 크면 실제로 할일 : window.scrollBy(0, -55); Y축(높이)만 뺀다.
// scroll양이 0이면 setInterval을 멈춘다.
var scrollInterval = setInterval(function () {
if (scrollPos > 0) {
window.scrollBy(0, -55);
} else {
clearInterval(scrollInterval);
}
}, 15);
}
</script>
</body>
</html>