Friday, October 4, 2019

Programming: JQuery, Javascript
Keynote of work: Add Smooth Scrolling

Type this code just before the ending tag of body (at last) if you want smooth scrolling, but before that it will be easy if you have selectors knowledge of CSS.
Code:

// Adding smooth scrolling
<script>
$('#main-nav a').on('click', function(e) {

//Check for hash value
if(this.hash !== ' ' ) {

// Prevent default behavior

e.preventDefault();

// Store hash value
const hash = this.hash;

//Animate smooth scrolling (make sure to use the full version of jquery)

$('html, body').animate({
scrollTop: $(hash).offset( ).top}, 900, function( ){

// Add hash to URL after the scroll
window.location.hash = hash;
});
</script>










Twitter Delicious Facebook Digg Stumbleupon Favorites More