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
// setting up options for IntersectionObserver | |
// setting threshold to .9, in this instance, means when 90% of the element is out of view | |
let options = { | |
root: null, | |
threshold: [.9] | |
} | |
// function with ternary operator to check if threshold is met then display none but if not then update display | |
function showToATC(entryArray){ | |
let div = document.getElementById('scroll-to-atc'); |
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
{% comment %} | |
Script to be included likely in product form snippet | |
Tried using intersection observer, and this may indeed be better, but issue with mobile and the button presenting too soon. Best solution at this time seems to be comparing scroll position and only showing when the offset is greater than the actual scroll position. | |
{% endcomment %} | |
<script> | |
const bodyRect = document.body.getBoundingClientRect(); | |
const btnRect = document.getElementById('atc-btn').getBoundingClientRect(); | |
const offset = btnRect.top - bodyRect.top; | |
window.addEventListener('scroll', showToATC, false); |
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
<script type="text/javascript"> | |
window.addEventListener('scroll', scrollyScroll, false); | |
function scrollyScroll() { | |
let scrollPosition = 0; | |
scrollPosition = window.scrollY; | |
if (scrollPosition > 10) { | |
(function() { | |
var tidScript = document.createElement('script'); | |
tidScript.type = 'text/javascript'; |
NewerOlder