কিভাবে সমস্ত গতিপ্রবাহ প্রভাব তৈরি করা যায়
কিভাবে CSS দিয়ে সমস্ত গতিপ্রবাহ প্রভাব তৈরি করা যায়
Smooth scrolling
Section 1
Click me, smooth scroll to the bottom part 2.Click the link to see the 'smooth' scrolling effect.
Note:Removing the scroll-behavior property can cancel smooth scrolling.
Smooth scrolling
Add scroll-behavior: smooth
You can enable smooth scrolling for the entire page:
Note:It can also be added to a specific element/scroll container.
Example
html { scroll-behavior: smooth; }
Browser support
The numbers in the table indicate the first browser version that fully supports the scroll-behavior property.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
61.0 | 79.0 | 36.0 | 14.0 | 48.0 |
cross-browser solution
for browsers that do not support scroll-behavior
browser, you can use JavaScript or JavaScript libraries (such as jQuery
<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) { // Ensure this.hash has a value before overriding default behavior if (this.hash !== "") { // Prevent default anchor click behavior event.preventDefault(); // Store hash value var hash = this.hash; // Use jQuery's animate() method to add smooth page scrolling // Optional number (800) specifies the milliseconds needed to scroll to the specified area $('html, body').animate({ scrollTop: $(hash).offset().top }, 800, function(){ // Complete scrolling, add hash (#) to URL (default click behavior) window.location.hash = hash; ); } // End if ); ); </script>