Intersection Observer

Size
2,070 Kb
Views
24,288

How do I make an intersection observer?

What is a intersection observer? How do you make a intersection observer? This script and codes were developed by Tyler Schwartz on 05 December 2022, Monday.

Intersection Observer Previews

Intersection Observer - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Intersection Observer</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <section id="section1" class="section section1">Section 1</section>
<section id="section2" class="section section2">Section 2</section>
<section id="section3" class="section section3">Section 3</section>
<section id="section4" class="section section4">Section 4</section>
<section id="section5" class="section section5">Section 5</section> <script src="js/index.js"></script>
</body>
</html>

Intersection Observer - Script Codes CSS Codes

/** * It seems odd that the default behaviour of IntersectionObserer * would allow both the first and second sections to be true when * the height of each section is set to 100vh. */
.section { -webkit-box-align: center; -ms-flex-align: center; align-items: center; display: -webkit-box; display: -ms-flexbox; display: flex; height: 100vh; /* the below fixes it */
/* height: calc(100vh + 1px); */ -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center;
}
.section1 { background-color: #DBDDE3;
}
.section2 { background-color: #CAD156;
}
.section3 { background-color: #336699;
}
.section4 { background-color: #D1630A;
}
.section5 { background-color: #606D6D;
}

Intersection Observer - Script Codes JS Codes

if (typeof IntersectionObserver === 'function') { const io = new IntersectionObserver(entries => { for(const entry of entries) { console.log(`${entry.target.id} is in view: ${entry.isIntersecting}`); } }); document.querySelectorAll('section').forEach(elem => io.observe(elem));
}
Intersection Observer - Script Codes
Intersection Observer - Script Codes
Home Page Home
Developer Tyler Schwartz
Username tschwartz
Uploaded December 05, 2022
Rating 3
Size 2,070 Kb
Views 24,288
Do you need developer help for Intersection Observer?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Tyler Schwartz (tschwartz) Script Codes
Create amazing sales emails with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!