Last active
May 23, 2021 16:37
-
-
Save ryandejaegher/078ffd5261daf200fb0cfe5841e2f8a4 to your computer and use it in GitHub Desktop.
Follow Along Links #squarespace #javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "scripts": [], | |
| "styles": [] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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> | |
| </head> | |
| <body> | |
| <div class="flex"> | |
| <h4>Yo</h4> | |
| <h4>What</h4> | |
| <h4>Up</h4> | |
| <h4>Fool</h4> | |
| </div> | |
| <div class="block"></div> | |
| <div class="flex"> | |
| <h3>Yo</h3> | |
| <h3>What</h3> | |
| <h3>Up</h3> | |
| <h3>Fool</h3> | |
| </div> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Highlighter = (function () { | |
| function createHighlight() { | |
| var span = document.createElement('span'); | |
| span.classList.add('highlight'); | |
| document.body.append(span); | |
| } | |
| function handleMouseOver(event) { | |
| console.log(event.target); | |
| var rect = event.target.getBoundingClientRect(); | |
| var highlight = document.querySelector('.highlight'); | |
| var cords = { | |
| width: `${rect.width}px`, | |
| height: `${rect.height}px`, | |
| top: `${rect.top + window.scrollY}px`, | |
| left: `${rect.left + window.scrollX}px` | |
| }; | |
| highlight.style.width = cords.width; | |
| highlight.style.height = cords.height; | |
| highlight.style.transform = `translate(${cords.left}, ${cords.top})`; | |
| console.log(highlight); | |
| } | |
| function init(target) { | |
| var highlightTargets = document.querySelectorAll(target); | |
| createHighlight(); | |
| highlightTargets.forEach(item => item.addEventListener('mouseover', handleMouseOver)); | |
| } | |
| return init; | |
| })(); | |
| var thang = Highlighter; | |
| thang('h4'); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| *, | |
| *:before, | |
| *:after { | |
| box-sizing: border-box; | |
| } | |
| html, | |
| body { | |
| height: 100%; | |
| margin: 0; | |
| font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', | |
| 'Helvetica Neue', sans-serif; | |
| } | |
| .block { | |
| height: 150vh; | |
| } | |
| .flex { | |
| display: flex; | |
| justify-content: center; | |
| align-items: center; | |
| height: 100%; | |
| gap: 20px; | |
| } | |
| h4 { | |
| padding: 2px; | |
| } | |
| .flex-col { | |
| flex-direction: column; | |
| } | |
| .highlight { | |
| display: inline-block; | |
| background: hotpink; | |
| opacity: 0.8; | |
| border-radius: 4px; | |
| position: absolute; | |
| top: 0; | |
| left: 0; | |
| transition: transform 0.2s ease; | |
| z-index: -1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment