Jump to content

How to make a button's function to scroll back to the top of the page

Recommended Posts

  • Replies 8
  • Views 1.3k
  • Created
  • Last Reply

Top Posters In This Topic

Posted

right now it reloads the page, but i was hoping for more for of a scroll-to-top effect. like it does on this page when you click the "TOP" button.

thanks!

15 hours ago, tuanphan said:

I see it already scroll to top when click?

 

Posted
On 5/31/2024 at 9:03 AM, MWR said:

right now it reloads the page, but i was hoping for more for of a scroll-to-top effect. like it does on this page when you click the "TOP" button.

thanks!

 

Try this code to bottom of Code Injection > Footer

<script>
  $(document).ready(function(){
    $('a#site-title').attr('href','#');
});
</script>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Posted
On 6/1/2024 at 11:30 PM, tuanphan said:

Try this code to bottom of Code Injection > Footer

<script>
  $(document).ready(function(){
    $('a#site-title').attr('href','#');
});
</script>

 

Hi again. thanks for sending that over. I pasted that into the code injection and it doesn't seem to do anything. I've left the code in, but is it possible that there's some other code injection that is cancelling it out? any help would be amazing thank you!

  • 5 months later...
Posted
On 6/4/2024 at 2:52 AM, Lesum said:

@MWR Hi! In addition to the code @tuanphan provided, add this code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

 

Hi @Lesum and @tuanphan, I tried using both bits of code, pasted in Code Injection > Footer, and it worked, scrolling back to the top of page one time, and then not again.  Any ideas?

I had some text, site name and logo in the footer already linked to reload the home page, so i removed those links to no affect.

www.rabih-hage.com

Thanks!

Posted
17 hours ago, WillC said:

I tried using both bits of code, pasted in Code Injection > Footer, and it worked, scrolling back to the top of page one time, and then not again.  Any ideas?

I had some text, site name and logo in the footer already linked to reload the home page, so i removed those links to no affect.

www.rabih-hage.com

Thanks!

You mean these?

image.thumb.png.3c96cdbf1dbbe09f1652f148652aae85.png

You can use this new code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
  $(document).ready(function() {
    $('#block-yui_3_17_2_1_1725539771143_4135, #block-yui_3_17_2_1_1729858790182_6852').on('click', function() {
        $('html, body').animate({ scrollTop: 0 }, 'slow');
    });
});
</script>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.