๐Ÿ’ปCoding/๐Ÿ“˜ JavaScript

JavaScript ์ˆซ์ž ์นด์šดํŠธ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋งŒ๋“ค๊ธฐ | ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ JS

์Œ์€์‘ 2023. 3. 15. 13:30
728x90
๋ฐ˜์‘ํ˜•
JavaScript 
์ˆซ์ž ์นด์šดํŠธ ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋งŒ๋“ค๊ธฐ
์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ JS
/
" ์›น์‚ฌ์ดํŠธ ํ™ˆํŽ˜์ด์ง€๋ฅผ ๋ณด๋ฉด
์ˆซ์ž๊ฐ€ ์˜ฌ๋ผ๊ฐ€๋ฉด์„œ ์นด์šดํŒ…๋˜๋ฉด์„œ
๊ณ ๊ฐ์˜ ์‹œ์„ ์„ ์žก๋Š” ํŽ˜์ด์ง€๊ฐ€ ์žˆ๋Š”๋ฐ,
JS ์นด์šดํŠธ ์• ๋‹ˆ๋ฉ”์ด์…˜์œผ๋กœ ๊ตฌํ˜„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.โœŒ๏ธ
๊ณ ๊ฐ์—๊ฒŒ ์–ดํ•„ํ•  ์ˆ˜ ์žˆ๋Š” ์ˆซ์ž ์นด์šดํŠธ ๊ตฌํ˜„ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.๐Ÿ˜Š"
/

โฌ‡๏ธโฌ‡๏ธโฌ‡๏ธ์˜์นด ํ™ˆํŽ˜์ด์ง€ ์ˆซ์ž ์นด์šดํŒ… ์˜ˆ์‹œโฌ‡๏ธโฌ‡๏ธโฌ‡๏ธ

โœ… ์ˆซ์ž ์นด์šดํŠธ ์• ๋‹ˆ๋ฉ”์ด์…˜ Code
โ†ช๏ธ HTML > CSS > JS
-
๐Ÿ“font : Montserrat
<!DOCTYPE html>
<html lang="ko">
<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>Number Count Animation</title>
    <!-- font -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@500&display=swap" rel="stylesheet">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@500&display=swap');

        .section10 {
            width: 100%;
            height: 400px;
            background: #f2f2f2;
        }

        .section10Text {
            font-family: 'Montserrat', sans-serif;
            font-style: normal;
            font-weight: 500;
            font-size: 35px;
            line-height: 52px;
            text-align: center;
            letter-spacing: -0.08em;
            /* border: 1px solid red; */
            position: relative;
            margin: 0;
            top: 50%;
            transform: translateY(-50%);
        }

        .colorBold,
        .countNum {
            color: #0071E3;
            font-weight: 700;
        }

        .countBold {
            font-weight: 700;
        }
    </style>

</head>

<body>
    <div class="section10">
        <p class="section10Text">
            <span class="countNum">0</span>๋ช…์˜ ํšŒ์›์ด ์˜์นด์™€
            <br>ํ•จ๊ป˜ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
            <br>์ง€๊ธˆ ๋ฐ”๋กœ <span class="colorBold">์˜์นด ๋“œ๋ผ์ด๋ธŒ</span>๋ฅผ ์‹œ์ž‘ํ•˜์„ธ์š”.
        </p>

    </div>

</body>

<script>
    const counter = ($counter, max) => {
        let now = max;

        const handle = setInterval(() => {
            $counter.innerHTML = Math.ceil(max - now);

            // ๋ชฉํ‘œ์ˆ˜์น˜์— ๋„๋‹ฌํ•˜๋ฉด ์ •์ง€
            if (now < 1) {
                clearInterval(handle);
            }

            // ์ฆ๊ฐ€๋˜๋Š” ๊ฐ’์ด ๊ณ„์†ํ•˜์—ฌ ์ž‘์•„์ง
            const step = now / 10;

            // ๊ฐ’์„ ์ ์šฉ์‹œํ‚ค๋ฉด์„œ ๋‹ค์Œ ์ฐจ๋ก€์— ์˜ํ–ฅ์„ ๋ผ์นจ
            now -= step;
        }, 50);
    }

    window.onload = () => {
        // ์นด์šดํŠธ๋ฅผ ์ ์šฉ์‹œํ‚ฌ ์š”์†Œ
        const $counter = document.querySelector(".countNum");

        // ๋ชฉํ‘œ ์ˆ˜์น˜
        const max = 8599184;
        setTimeout(() => counter($counter, max), 2000);

    }
</script>

</html>

728x90
๋ฐ˜์‘ํ˜•