<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="css/스크롤 이벤트.css">
</head>
<body>
    <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'),
        // document.documentElement는 문서 자체를 가져온다
            docElem = document.documentElement,
            offset,
            scrollPos, // 스크롤 해서 위로 올라가있는 문서의 길이
            docHeight; // 문서의 높이
            
            // 문서 높이 계산하기 (scrollHeight 또는 offsetHeight)
            docHeight = Math.max(docElem.scrollHeight, docElem.offsetHeight);
            
            
            if(docHeight != 0) {
                offset = docHeight / 4;
            }

            // 스크롤 이벤트 추가
            window.addEventListener('scroll', function() {
                scrollPos = docElem.scrollTop;
                console.log(scrollPos);
                
                // 클래스 명을 설정하는 방법
                // btt.className = 'test';
                btt.className = (scrollPos > offset) ? 'visible' : '';
            });
            
            
            // 클릭 이벤트 추가
            btt.addEventListener('click', function(ev) {
                ev.preventDefault(); // 링크의 기본 기능을 막는다.
                // docElem.scrollTop = 0;
                scrollToTop();
            });

            function scrollToTop() {
                // 일정시간 마다 할 일
                // var scrollInterval = setInterval(할 일, 시간);
                // 0.0015s = 15
                // 할 일 = function() {실제로 할 일}
                // 윈도우의 스크롤 양이 0이 아닐 때 실제로 할 일 window.scrollBy(0,-55);
                // 스크롤의 양이 0이면 setInterval을 멈춰라. clearInterval(이름);
                
                var scrollInterval = setInterval(function () {
                    (scrollPos != 0) ? window.scrollBy(0, -55) : clearInterval(scrollInterval);
                }, 15);
            }
    </script>
</body>
</html>

+ Recent posts