I'm attempting to recreate the interactive widget titled "Engage. Involve. Connect" found on this webpage: . The concept involves the widget remaining fixed at the bottom of the page until the user scrolls, at which point it dynamically positions itself just above the text that reads "Experiences shape us."
Currently, I am developing a similar widget for my site located at . However, I am encountering challenges in ensuring the #widget / #unanchored element stops scrolling once it reaches the ".xp" class, contained within the "Experiences shape us." section.
This is the JavaScript code I am working with:
window.addEventListener('scroll', function() {
var widget = document.getElementById('widget');
var xpElement = document.querySelector('.xp');
var widgetHeight = widget.offsetHeight;
var xpPosition = xpElement.getBoundingClientRect().top;
var windowHeight = window.innerHeight;
var distance = xpPosition - windowHeight + widgetHeight;
if (distance <= 0) {
// Un-anchor and scroll with content
widget.classList.add('unanchored');
} else {
// Keep anchored
widget.classList.remove('unanchored');
}
// Dynamically set height of .xp element
xpElement.style.setProperty('--xp-height', widgetHeight + 'px');
});
Here is the corresponding HTML:
<h3 id="widget" class="wp-block-heading has-text-align-center frontpage ticss-f97cde6b has-white-color has-text-color has-background" style="background-color:#00000087;font-size:39px">Engage. Involve. Connect.<br><span class="text frontpage2" style="font-weight: 200 !important;">We fuse Art + Engineering to create world-class experiences.</span><br><a href="https://williamh117.sg-host.com/#spacestop"><i class="arrow down"></i></a></h3>
And here is the CSS:
.unanchored {
position: fixed !important;
bottom: 300px !important;
top: calc(100% - var(--widget-height) - 30px);
left: 0 !important;
margin-bottom:0px !important;
}
.xp {
--widget-height: 30px;
position: relative;
}
#widget {
position: fixed;
bottom: 0;
left: 0;
background-color: #f0f0f0;
width: 100%;
text-align: center;
transition: bottom 0.3s ease-in-out;
z-index:1000 !important;
scroll-behavior: smooth !important;
}
Your advice and assistance are greatly appreciated. Thank you!