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
| // bad | |
| var firstname = 'gp'; | |
| // bad | |
| var first_name = 'gp'; | |
| // bad | |
| var FIRSTNAME = 'gp'; | |
| // bad |
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
| // bad | |
| var firstname = 'GP'; | |
| // bad | |
| var first_name = 'GP'; | |
| // bad | |
| var FIRSTNAME = 'GP'; | |
| // bad |
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
| // bad | |
| var value = 'GP'; | |
| // bad | |
| var val = 'GP'; | |
| // good | |
| var firstName = 'GP'; |
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 name = "GP LEE"; | |
| var Name = "Tim Lee"; | |
| var NAME = "Thomas Lee" | |
| console.log(name); | |
| // GP LEE | |
| console.log(Name); | |
| // Tim Lee |
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
| const images = document.querySelectorAll('.lazyload'); | |
| function handleIntersection(entries) { | |
| entries.map((entry) => { | |
| if (entry.isIntersecting) { | |
| entry.target.src = entry.target.dataset.src; | |
| entry.target.classList.add('loaded') | |
| observer.unobserve(entry.target); | |
| } | |
| }); |
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
| function intersectionHandler(entry) { | |
| const id = entry.target.id; | |
| const currentlyActive = document.querySelector('nav li.active'); | |
| const shouldBeActive = document.querySelector('nav li[data-ref=' + id + ']'); | |
| if (currentlyActive) { | |
| currentlyActive.classList.remove('active'); | |
| } | |
| if (shouldBeActive) { | |
| shouldBeActive.classList.add('active'); |
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
| const sections = document.querySelectorAll('div.screen'); | |
| const config = { | |
| rootMargin: '-50px 0px -55%' | |
| }; | |
| let observer = new IntersectionObserver(function (entries, self) { | |
| entries.forEach(entry => { | |
| console.log(entry); | |
| if (entry.isIntersecting) { | |
| intersectionHandler(entry); |
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
| .screen { | |
| min-height: 100vh; | |
| text-align:center; | |
| text-transform: uppercase; | |
| position: relative; | |
| } | |
| .screen h1 { | |
| margin:0; | |
| padding:0; | |
| white-space: nowrap; |
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
| <div class="screen" id="first-screen"> | |
| <h1>First screen</h1> | |
| </div> | |
| <div class="screen" id="second-screen"> | |
| <h1>Second Screen</h1> | |
| </div> | |
| <div class="screen" id="third-screen"> | |
| <h1>Third Screen</h1> | |
| </div> |
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
| function handleIntersect(entries, observer) { | |
| entries.forEach((entry) => { | |
| if (entry.intersectionRatio > prevRatio) { | |
| entry.target.style.backgroundColor = increasingColor.replace("ratio", entry.intersectionRatio); | |
| } else { | |
| entry.target.style.backgroundColor = decreasingColor.replace("ratio", entry.intersectionRatio); | |
| } | |
| prevRatio = entry.intersectionRatio; | |
| }); |