Show the Alhena chat widget only after the user scrolls down the page, reducing initial visual clutter.
This example shows how to hide the chat widget on initial page load and only show it after the user scrolls down. This is useful for landing pages or content-heavy sites where you want to minimize distractions while still offering support.
What You'll Learn
Hide the widget on initial page load using CSS
Detect scroll events
Show the widget after a scroll threshold
Control widget visibility programmatically
Use Case
Showing the chat widget immediately can:
Distract users from your content
Increase perceived page load time
Feel intrusive on landing pages
By delaying the widget until the user scrolls, you:
Let users engage with your content first
Indicate the user is actively browsing
Show support when it's more likely to be needed
Code Example
How It Works
CSS hiding: The #helix-chat-container element is hidden with display: none
Scroll listener: We listen for scroll events on the window
Threshold check: When scroll position exceeds the threshold (100px by default), show the widget
One-time trigger: Remove the scroll listener after showing to avoid unnecessary checks
Fallback timeout: Show the widget after 30 seconds even without scroll (for users who don't scroll)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scroll-Triggered Widget Example</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 40px;
line-height: 1.6;
}
.content {
max-width: 800px;
margin: 0 auto;
}
/* Hide widget initially */
#helix-chat-container {
display: none;
}
</style>
</head>
<body>
<div class="content">
<h1>Welcome to Our Website</h1>
<p>Scroll down to see more content...</p>
<!-- Tall content to enable scrolling -->
<div style="height: 1500px; background: linear-gradient(#f5f5f5, #e0e0e0); padding: 20px; margin: 20px 0;">
<p>This is placeholder content. The chat widget will appear after you scroll down a bit.</p>
</div>
<h2>More Content Here</h2>
<p>The chat widget should now be visible.</p>
</div>
<!-- Alhena SDK -->
<script>
document.gleenConfig = {
company: 'your-company-key',
apiBaseUrl: 'https://app.alhena.ai'
};
</script>
<script src="https://app.alhena.ai/sdk/gleenWidget.js"></script>
<!-- Scroll detection logic -->
<script>
(function() {
var widgetShown = false;
var scrollThreshold = 100; // pixels
function showChatWidget() {
if (widgetShown) return;
var container = document.getElementById('helix-chat-container');
if (container) {
container.style.display = 'block';
widgetShown = true;
console.log('Chat widget shown after scroll');
}
}
function handleScroll() {
var scrollPosition = window.scrollY || window.pageYOffset;
if (scrollPosition > scrollThreshold) {
showChatWidget();
// Remove listener after showing (optimization)
window.removeEventListener('scroll', handleScroll);
}
}
window.addEventListener('scroll', handleScroll);
// Also show after a timeout as fallback
setTimeout(function() {
showChatWidget();
}, 30000); // Show after 30 seconds regardless of scroll
})();
</script>
</body>
</html>
var scrollThreshold = 300; // Show after scrolling 300px
function handleScroll() {
var scrollPercent = (window.scrollY / (document.body.scrollHeight - window.innerHeight)) * 100;
if (scrollPercent > 25) { // After scrolling 25% of the page
showChatWidget();
window.removeEventListener('scroll', handleScroll);
}
}
function handleScroll() {
var targetElement = document.getElementById('support-section');
var elementTop = targetElement.getBoundingClientRect().top;
var windowHeight = window.innerHeight;
if (elementTop < windowHeight) {
showChatWidget();
window.removeEventListener('scroll', handleScroll);
}
}