@@ -2,39 +2,36 @@ import { Component } from "@ribajs/core";
22import { debounceF } from "@ribajs/utils/src/control.js" ;
33import { hasChildNodesTrim } from "@ribajs/utils/src/dom.js" ;
44
5- const VISIBLE_SCROLL_START = 0.1 ; // show after 10% from top
6- const VISIBLE_SCROLL_END = 0.9 ; // hide again in last 10%
5+ const HIDE_SCROLL_END = 0.9 ; // hide in last 10% of scroll range
76
87/**
9- * Wrapper component that shows its child content only when the page is scrolled
10- * in the "middle" 80% (between 10% and 90% of scroll range). Use for fixed
11- * elements like a call button that should be hidden near the top and bottom.
12- * Pass the content as child nodes (like dfw-contact-map).
8+ * Fixed call button component that shows the button at the top of the page
9+ * and hides it only when the user scrolls to the bottom (last 10%).
1310 */
14- export class DfwScrollVisibilityComponent extends Component {
15- public static tagName = "dfw-scroll-visibility " ;
11+ export class DfwFixedCallButtonComponent extends Component {
12+ public static tagName = "dfw-fixed-call-button " ;
1613
1714 protected autobind = true ;
1815
1916 static get observedAttributes ( ) : string [ ] {
2017 return [ ] ;
2118 }
2219
20+ public scope : Record < string , never > = { } ;
21+
2322 private debouncedUpdateVisibility ! : ( ) => void ;
2423 private readonly boundUpdateVisibility = ( ) => this . debouncedUpdateVisibility ( ) ;
2524
2625 protected connectedCallback ( ) {
2726 super . connectedCallback ( ) ;
28- this . setAttribute ( "data-visible" , "false " ) ;
29- this . init ( DfwScrollVisibilityComponent . observedAttributes ) ;
27+ this . setAttribute ( "data-visible" , "true " ) ;
28+ this . init ( DfwFixedCallButtonComponent . observedAttributes ) ;
3029
3130 this . debouncedUpdateVisibility = debounceF ( ( ) => {
3231 if ( ! this . isConnected ) return ;
3332 const maxScroll = document . documentElement . scrollHeight - window . innerHeight ;
34- const visible =
35- maxScroll <= 0 ||
36- ( window . scrollY >= maxScroll * VISIBLE_SCROLL_START &&
37- window . scrollY <= maxScroll * VISIBLE_SCROLL_END ) ;
33+ // Hide only in the last 10% of scroll range, visible everywhere else (including top)
34+ const visible = maxScroll <= 0 || window . scrollY <= maxScroll * HIDE_SCROLL_END ;
3835 this . setAttribute ( "data-visible" , visible ? "true" : "false" ) ;
3936 } ) ;
4037 }
@@ -58,6 +55,6 @@ export class DfwScrollVisibilityComponent extends Component {
5855 if ( hasChildNodesTrim ( this ) ) {
5956 return null ;
6057 }
61- return `<p>Provide child content to show in the middle 80% scroll range .</p>` ;
58+ return `<p>Provide child content for the fixed call button .</p>` ;
6259 }
6360}
0 commit comments