Skip to main content
Known Participant
March 12, 2025
Answered

Smooth Scroll on website

  • March 12, 2025
  • 2 replies
  • 300 views

On the template for my new website, it has a smooth scroll function which when clicked on, for example 'view my protfolio' at the top moves down the page to the relevant section clicked on.

 

However, I am finding this way too slow but can't find in the code where to amend the delay so it scrolls quicker? It seems to sit in 'animate.min.css' but I don't see any timings there.

 

url: https://kylehawkinscreative.com/

Correct answer BenPleysier

Have a look in /js/theme.js

 

/*------------------------
   Scroll to top
-------------------------- */
$(function () {
		$(window).on('scroll', function(){
			if ($(this).scrollTop() > 400) {
				$('#back-to-top').fadeIn();
			} else {
				$('#back-to-top').fadeOut();
			}
		});
		});
$('#back-to-top').on("click", function() {
	$('html, body').animate({scrollTop:0}, 'slow');
	return false;
});

 

This is written using  jQuery, a framwork that has gone out of fashion.

 

I converted a similar template to using NodeJS and created a very simple script for the Floating back-to-top button:

<!-- =====Floating back-to-top button===== -->
<button type="button" class="btn btn-primary position-fixed bottom-0 end-0 m-4 rounded-circle" onclick="window.scrollTo({top: 0, behavior: 'smooth'})" style="width: 50px; height: 50px; z-index: 1000; display: none;" id="backToTop">
    <i class="fas fa-arrow-up"></i>
</button>
<script>
    window.onscroll = function() {
    if (document.body.scrollTop > 400 || document.documentElement.scrollTop > 400) {
        document.getElementById("backToTop").style.display = "block";
    } else {
        document.getElementById("backToTop").style.display = "none";
    }
};
</script>

2 replies

Known Participant
March 12, 2025

Brilliant, found it and managed to alter the speed. Thank you.

BenPleysier
Community Expert
BenPleysierCommunity ExpertCorrect answer
Community Expert
March 12, 2025

Have a look in /js/theme.js

 

/*------------------------
   Scroll to top
-------------------------- */
$(function () {
		$(window).on('scroll', function(){
			if ($(this).scrollTop() > 400) {
				$('#back-to-top').fadeIn();
			} else {
				$('#back-to-top').fadeOut();
			}
		});
		});
$('#back-to-top').on("click", function() {
	$('html, body').animate({scrollTop:0}, 'slow');
	return false;
});

 

This is written using  jQuery, a framwork that has gone out of fashion.

 

I converted a similar template to using NodeJS and created a very simple script for the Floating back-to-top button:

<!-- =====Floating back-to-top button===== -->
<button type="button" class="btn btn-primary position-fixed bottom-0 end-0 m-4 rounded-circle" onclick="window.scrollTo({top: 0, behavior: 'smooth'})" style="width: 50px; height: 50px; z-index: 1000; display: none;" id="backToTop">
    <i class="fas fa-arrow-up"></i>
</button>
<script>
    window.onscroll = function() {
    if (document.body.scrollTop > 400 || document.documentElement.scrollTop > 400) {
        document.getElementById("backToTop").style.display = "block";
    } else {
        document.getElementById("backToTop").style.display = "none";
    }
};
</script>
Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!