Skip to content

Instantly share code, notes, and snippets.

View gpDA's full-sized avatar
🏠
Working from home

GP LEE gpDA

🏠
Working from home
View GitHub Profile
// bad
var firstname = 'gp';
// bad
var first_name = 'gp';
// bad
var FIRSTNAME = 'gp';
// bad
// bad
var firstname = 'GP';
// bad
var first_name = 'GP';
// bad
var FIRSTNAME = 'GP';
// bad
// bad
var value = 'GP';
// bad
var val = 'GP';
// good
var firstName = 'GP';
var name = "GP LEE";
var Name = "Tim Lee";
var NAME = "Thomas Lee"
console.log(name);
// GP LEE
console.log(Name);
// Tim Lee
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);
}
});
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');
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);
.screen {
min-height: 100vh;
text-align:center;
text-transform: uppercase;
position: relative;
}
.screen h1 {
margin:0;
padding:0;
white-space: nowrap;
<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>
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;
});