Is There Way To Scroll To Anchor Rather Than Jump With Javascript (something Like Smooth Scroll)
Solution 1:
Add jQuery library.
Use the following script to do a smooth scroll to the target element you want.
jQuery('html,body').animate({scrollTop: jQuery('#target').offset().top}, 1000);
target
is the id of the target element and 1000
is the duration of the animation.
Solution 2:
Solution 3:
Use this code and enjoy
$(document).ready(function(){
$("#btop").hide(); // replace only #btop with your <div id=" ">
$(function(){
$(window).scroll(function(){
if ($(this).scrollTop()>100){
$('#btop').fadeIn(); // replace only #btop with your <div id=" ">
}
else{
$('#btop').fadeOut(); // replace only #btop with your <div id=" ">
}
});
$('#btop a').click(function(){ // replace only #btop with your <div id=" ">
$('body,html').animate({
scrollTop:0
},200); // to speed up scroll replace 200 to 300 or 500returnfalse;
});
});
});
Solution 4:
You may want to check out this tutorial or google for "JS smooth scroll"
Solution 5:
There is no built-in smooth scrolling in JavaScript so you would have to implement it yourself -- but why re-invent the wheel if you already have it in jQuery and you probably won't have to add more than two or three lines of code? Just download jQuery and the ScrollTo plugin, add them to your <head>
section in a <script>
tag and then use this to scroll to an element with a given ID:
$.scrollTo("#my-element-id");
This will scroll to the element whose ID is my-element-id
so you have to use the id=...
attribute in the anchors and not the name=...
attribute.
If you wish to add this behaviour automatically to all your anchors within a given div
(or to the entire page), you can use the LocalScroll plugin which makes the entire this as simple as:
$.localScroll();
Post a Comment for "Is There Way To Scroll To Anchor Rather Than Jump With Javascript (something Like Smooth Scroll)"