• Resolved bradhip

    (@bradhip)


    Is there any way to make the Sidebar fixed, or stay on the screen when a person scrolls? Right now, when you scroll the sidebar goes up and out of sight.

    Thank you for any assistance. ??

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Theme Author Greenlet Team

    (@greenlet)

    Hi @bradhip
    This feature is not available in the Greenlet theme. Thanks for this, we will add it to our roadmap.

    Currently, you can implement this functionality by adding code like this to your child theme’s function.php:

    function sticky_script() {
    	?>
    	<script type="text/javascript">
    		const topOffset = 100
    		const bottomOffset = 200
    		const sidebars = document.querySelectorAll( '.sidebar' )
    		const bodyHeight = document.body.offsetHeight
    		let stuck = false
    		function stick() {
    			sidebars.forEach( ( sidebar ) => {
    				if ( stuck && ( bodyHeight - sidebar.offsetHeight - bottomOffset ) < window.scrollY ) return
    				if ( window.scrollY > topOffset ) {
    					stuck = true
    					sidebar.style.position = 'relative'
    					sidebar.style.height = 'fit-content'
    					sidebar.style.top = <code>${ window.scrollY - topOffset }px</code>
    				}
    			} )
    		}
    
    		document.addEventListener( 'scroll', stick )
    	</script>
    	<?php
    }
    add_action( 'wp_footer', 'sticky_script' );

    Please change topOffset and bottomOffset according to your needs. Please let us know if you face any issues.

    Hope that helps!

Viewing 1 replies (of 1 total)
  • The topic ‘Can the Sidebar stay on screen during scroll?’ is closed to new replies.