Give the people confetti ๐
This file contains 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
<script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.4.0/dist/confetti.browser.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> | |
<div id="bottom_of_page">Thanks for scrolling to the bottom ๐</div> | |
<div>Enjoy some confetti ๐</div> | |
<script> | |
/* | |
Show confetti if they scroll to the bottom of the report | |
*/ | |
function showConfetti() { | |
// Docs: https://www.npmjs.com/package/canvas-confetti | |
confetti({ | |
particleCount: 150, | |
spread: 150, | |
origin: { | |
y: 1 | |
} | |
}); | |
} | |
// From stack overflow: | |
// https://stackoverflow.com/questions/123999/how-can-i-tell-if-a-dom-element-is-visible-in-the-current-viewport/7557433#7557433 | |
$.fn.inView = function() { | |
if (!this.length) | |
return false; | |
var rect = this.get(0).getBoundingClientRect(); | |
return ( | |
rect.top >= 0 && | |
rect.left >= 0 && | |
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && | |
rect.right <= (window.innerWidth || document.documentElement.clientWidth) | |
); | |
}; | |
window.didTheyGetConfetti = false; | |
$(window).on('scroll', function() { | |
// if( $('#text_c2e50381-0d2e-4596-9324-8082b0498732').inView() ) { | |
if ($('#bottom_of_page').inView()) { | |
if (!window.didTheyGetConfetti) { | |
showConfetti() | |
window.didTheyGetConfetti = true; | |
} | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment