상세 컨텐츠

본문 제목

12_포인트 글!

Javascript

by 모모87 2021. 3. 13. 02:43

본문

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title>👀👀👀Follow Along Nav</title>
        <link rel="stylesheet" href="style.css" />
    </head>
    <body>
        <nav>
            <ul class="menu">
                <li><a href="">Home</a></li>
                <li><a href="">Order Status</a></li>
                <li><a href="">Tweets</a></li>
                <li><a href="">Read Our History</a></li>
                <li><a href="">Contact Us</a></li>
            </ul>
        </nav>

        <div class="wrapper">
            <p>Lorem ipsum dolor sit amet, <a href="">consectetur</a> adipisicing elit. Est <a href="">explicabo</a> unde natus necessitatibus esse obcaecati distinctio, aut itaque, qui vitae!</p>
            <p>Aspernatur sapiente quae sint <a href="">soluta</a> modi, atque praesentium laborum pariatur earum <a href="">quaerat</a> cupiditate consequuntur facilis ullam dignissimos, aperiam quam veniam.</p>
            <p>Cum ipsam quod, incidunt sit ex <a href="">tempore</a> placeat maxime <a href="">corrupti</a> possimus <a href="">veritatis</a> ipsum fugit recusandae est doloremque? Hic, <a href="">quibusdam</a>, nulla.</p>
            <p>Esse quibusdam, ad, ducimus cupiditate <a href="">nulla</a>, quae magni odit <a href="">totam</a> ut consequatur eveniet sunt quam provident sapiente dicta neque quod.</p>
            <p>Aliquam <a href="">dicta</a> sequi culpa fugiat <a href="">consequuntur</a> pariatur optio ad minima, maxime <a href="">odio</a>, distinctio magni impedit tempore enim repellendus <a href="">repudiandae</a> quas!</p>
        </div>

        <script>
            const triggers = document.querySelectorAll('a');
            const highlight = document.createElement('span');
            highlight.classList.add('highlight');
            document.body.appendChild(highlight);

            function highlightLink() {
                const linkCoords = this.getBoundingClientRect();
                console.log(linkCoords);
                const coords = {
                    width: linkCoords.width,
                    height: linkCoords.height,
                    top: linkCoords.top + window.scrollY,
                    left: linkCoords.left + window.scrollX,
                };

                highlight.style.width = `${coords.width}px`;
                highlight.style.height = `${coords.height}px`;
                highlight.style.transform = `translate(${coords.left}px, ${coords.top}px)`;
            }

            triggers.forEach((a) => a.addEventListener('mouseenter', highlightLink));
        </script>
    </body>
</html>
반응형

'Javascript' 카테고리의 다른 글

14_뮤직플레이어  (0) 2021.03.13
13_자기소개 낙녹  (0) 2021.03.13
11_말하면 회의록이 작성되요!  (0) 2021.03.13
10_웹캠사진찍기  (0) 2021.03.13
09_커스텀컨트롤플레이어  (0) 2021.03.13

관련글 더보기