Div follow pages as user scrolls

Not sure why this code would not work

jQuery(document).ready(function($){

            var $body = $('body');
            var $outer = $('#content');
            var $follow = $('#follow');
            
            var followHt = $follow.height();
            
            var minY = $outer.offset().top;
            var maxY = minY + $outer.height() - followHt;
            
            $(window).scroll(function(){
                var yoff = $(#follow).scrollTop();
                if (yoff > maxY) {
                    yoff = maxY;
                }
                else if (yoff < minY) {
                    yoff = minY;
                }
                $follow.css('top', yoff);
            });    
            $follow.css('top', minY);
});

& have a inside <div id="content" class="site-content">
this smaller div

```<div id="follow" class="follow" >follow you</div>```

follow is positioned absolutely, content has height of 100%.
as i scroll down follow should do that. follow. but it doesn’t
thx
D

better yet…trying to rewrite the code starting with this, if the horizonatal scroll top is less than 200px for exmpale. the follow div should not display. but if it goes below that it display.

jQuery(document).ready(function($){
	var follow = $("#follow");
	var windowHeight = $(window).height();

	
	$('html,body').scrollTop(); 
	function scroll(){
		if(window.height =< 200){
			follow.css("display:","none");
		}else{
			follow.css("display:","block");
			follow.css("background:","white");
		};
	};
});

never mind. solved.
used a fixed position in css and jquery to bring user back to top if needed.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.