Skip to content

Commit

Permalink
use intersectionObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
Ritwik Srivastava committed May 29, 2024
1 parent 0288ab3 commit a35e454
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions blocks/floatingagent/floatingagent.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,18 @@ export default function decorate(block) {

const displayedElement = document.querySelector('.floatingagent');

window.addEventListener('scroll', () => {
const heroElement = document.querySelector('.hero-wrapper');
const heroRect = heroElement.getBoundingClientRect();
const heroElement = document.querySelector('.hero-wrapper');

if (heroRect.bottom < 0) {
displayedElement.style.display = 'flex';
} else {
displayedElement.style.display = 'none';
}
const observer = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
displayedElement.style.display = 'none';
} else {
displayedElement.style.display = 'flex';
}
});
}, {
threshold: [0],
});

observer.observe(heroElement);

0 comments on commit a35e454

Please sign in to comment.