AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

jQuery scroll smooth


<< Previous Page
jQuery tutorial
Next Page >>
jQuery tutorial

jQuery Tutorial » jQuery scroll() smooth

What is jQuery scroll smooth?

Scroll smooth is an element that allows you to scroll smoothly. The typical standard thing is a bit hectic and it might stop suddenly.

How do I make my scroll smoother?

We regularly use # (hash) inside the href feature of the HTML anchor tag to connect to a specific segment of a site page. For example, to search at the top of the current page, you can use <a href="#top"> and <a href="#bottom"> to search at the bottom of the page.
Clicking a connection, with the # will in a split second take you to a predefined area on the page.

 

jQuery Smooth Scroll to ID / Div

by utilizing ID also as we can utilize div components. You can likewise include movement page scroll utilizing jQuery animate () strategy.

In this tutorial, we'll tell you the best way to get a smooth look of div using jQuery without running.

<!DOCTYPE html>
<html>
<head>
<title>
Hi welcome in JQuery smooth Scrolling WebPage
</title>
<script src=
"https://code.jQuery.com/jQuery-3.4.1.min.js">
</script>
<style>
.scroll {
height: 1200px;
width:300px;
background-color: #FF9;
}
</style>
</head>
<body>
<h1 style="color: rgb(19, 27, 19)">
JQuery Smooth Scrolling
</h1>
<b>
This is the landing page of scrolling
</b>
<p id="end">
Click on below button to scroll the top of page
</p>
<p class="scroll">
Hi Welcome................
</p>
<a href="#end">
<strong>Click here to scroll the top of the page </strong></a>
<script>
let anchorSelector = 'a[href^="#"]';
$(anchorSelector).on('click', function (e) {
e.preventDefault();
let destination = $(this.hash);
let scrollPosition
= destination.offset().top;
let animationDuration = 700;
$('html, body').animate({
scrollTop: scrollPosition
}, animationDuration);
});
</script>
</body>
</html>

 

Related subjects:
jQuery slideUp jQuery fadeout Effects hide / show jQuery selectors

 

Tags: jquery scroll smooth, smooth scroll to div, smooth scroll jquery plugin, jquery smooth scroll to anchor, to element, to tp[, anchor offset, mouse wheel, jquery smooth scroll to element with offset
How do I make my scroll smoother?
How do I create a smooth scrolling anchor link?
How do you add a scrolling page in HTML?
How do you navigate to another page with a smooth scroll on a specific ID?

 

jquery scroll smooth to element - Example

We could use JavaScript or a JavaScript library as jQuery, to create scroll smooth to element that will work for all browsers:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
// Add smooth scrolling to all links
$("a").on('click', function(event) {

// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();

// Store hash
var hash = this.hash;

// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){

// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
} // End if
});
});
</script>
<style>
#section1 {
height: 600px;
background-color: pink;
}

#section2 {
height: 600px;
background-color: yellow;
}
</style>
</head>
<body>

<h1>Smooth Scroll</h1>

<div class="main" id="section1">
<h2>Section 1</h2>
<p>Click on the link to see the "smooth" scrolling effect.</p>
<a href="#section2">Click Me to Smooth Scroll to Section 2 Below</a>
<p>Note: Remove the scroll-behavior property to remove smooth scrolling.</p>
</div>

<div class="main" id="section2">
<h2>Section 2</h2>
<a href="#section1">Click Me to Smooth Scroll to Section 1 Above</a>
</div>

</body>
</html>

 

Smooth Scrolling With CSS & JavaScript

We’ll start with a pure CSS solution and then move on to a common jQuery approach for creating this functionality. Next, we’ll get rid of jQuery and discuss two pure JavaScript solutions.

 



jquery scroll smooth, smooth scroll to div, smooth scroll jquery plugin, jquery smooth scroll to anchor, to element, to tp[, anchor offset, mouse wheel, jquery smooth scroll to element with offset
How do I make my scroll smoother?
How do I create a smooth scrolling anchor link?
How do you add a scrolling page in HTML?

JQuery scroll smooth - jquery

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


0
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.