• Resolved garyholmgren

    (@garyholmgren)


    Hi, So on my site I have been having an issue I cannot solve. I have a button titled “projects” near the top of my page which is linked to an anchor in the projects section of my page. It only works properly when the page is scrolled all the way to the top, but as soon as I scroll down a little and then try pressing the button, it doesn’t scroll exactly to the anchor and seems to be offset by whatever amount I scroll the page to.

    I tried every setting in the ps2id menu and It didn’t change anything. Any suggestions?

    Thanks!

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author malihu

    (@malihu)

    Hello,

    There’s a CSS rule in your theme that sets the HTML overflow to hidden. This prevents the plugin from working properly. I’m not sure why this rule is there because it doesn’t affect the page design/layout.

    To fix it, simply add the following to your additional/custom CSS:

    html{
        overflow: visible;
    }

    Let me know

    Thread Starter garyholmgren

    (@garyholmgren)

    That does seem to fix it but then my scroll to top button disappears for some reason, and my page also wont autoscroll to top on refresh when adding that CSS

    Plugin Author malihu

    (@malihu)

    I see.

    The scroll to top button disappearing can be fixed with a bit of javascript.

    The page autoscroll to top on refresh can also be done with javascript but it is not standard browser behavior. Normally, when users refresh the page they expect to stay on the position they had scrolled to. I’m not sure why we would want to change that(?)

    So, if you can add custom javascript in your pages, this is the script for the scroll to top button:

    <script>
    (function($){
    	$(window).on("scroll",function(){
    		var $this=$(this),
    			$lmpixelsScrollToTop=$(".lmpixels-scroll-to-top");
    		$lmpixelsScrollToTop.toggleClass("hidden-btn", $this.scrollTop() < 150);
    	});
    })(jQuery);
    </script>

    If also you want the scroll to top on page refresh behavior, change the script to:

    <script>
    (function($){
    	$(window).on("load beforeunload",function(){
    		$(this).scrollTop(0);
    	}).on("scroll",function(){
    		var $this=$(this),
    			$lmpixelsScrollToTop=$(".lmpixels-scroll-to-top");
    		$lmpixelsScrollToTop.toggleClass("hidden-btn", $this.scrollTop() < 150);
    	});
    })(jQuery);
    </script>

    You can add the script in your template (e.g. in your theme/child-theme footer.php) or in a custom javascript box (without the <script></script> tags) if your theme (or some other plugin) provides one.

    I can also give you the PHP code if you want to add the script via functions.php, so let me know.

    Thread Starter garyholmgren

    (@garyholmgren)

    That worked wonderfully. I really appreciate your help with this!

    Plugin Author malihu

    (@malihu)

    Glad I helped ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Button wont scroll to anchor if page is slightly moved’ is closed to new replies.