|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <title>👀👀👀Follow Along Nav</title> |
| 6 | + <link rel="stylesheet" href="style.css"> |
| 7 | +</head> |
| 8 | +<body> |
| 9 | + |
| 10 | + <nav> |
| 11 | + <ul class="menu"> |
| 12 | + <li><a href="">Home</a></li> |
| 13 | + <li><a href="">Order Status</a></li> |
| 14 | + <li><a href="">Tweets</a></li> |
| 15 | + <li><a href="">Read Our History</a></li> |
| 16 | + <li><a href="">Contact Us</a></li> |
| 17 | + </ul> |
| 18 | + </nav> |
| 19 | + |
| 20 | + <div class="wrapper"> |
| 21 | + <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> |
| 22 | + <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> |
| 23 | + <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> |
| 24 | + <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> |
| 25 | + <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> |
| 26 | + </div> |
| 27 | + |
| 28 | +<script> |
| 29 | + const triggers = document.querySelectorAll('a'); |
| 30 | + const highlight = document.createElement('span'); |
| 31 | + highlight.classList.add('highlight'); |
| 32 | + document.body.appendChild(highlight); |
| 33 | + |
| 34 | + function highlightLink() { |
| 35 | + const linkCoords = this.getBoundingClientRect(); |
| 36 | + console.log(linkCoords); |
| 37 | + const coords = { |
| 38 | + width: linkCoords.width, |
| 39 | + height: linkCoords.height, |
| 40 | + top: linkCoords.top + window.scrollY, |
| 41 | + left: linkCoords.left + window.scrollX |
| 42 | + }; |
| 43 | + |
| 44 | + highlight.style.width = `${coords.width}px`; |
| 45 | + highlight.style.height = `${coords.height}px`; |
| 46 | + highlight.style.transform = `translate(${coords.left}px, ${coords.top}px)`; |
| 47 | + |
| 48 | + } |
| 49 | + |
| 50 | + triggers.forEach(a => a.addEventListener('mouseenter', highlightLink)); |
| 51 | + |
| 52 | +</script> |
| 53 | +</body> |
| 54 | +</html> |
| 55 | + |
0 commit comments