admin管理员组文章数量:1425689
in one page, if we have html like this
and we click on tag it will navigate to particular section, that's fine
<a href="#shushi">Sushi</a>
<a href="#bbq">BBQ</a>
Sample Page:
<div id='sushi'></div>
<div id='bbq'></div>
but is it possible to add some animation effect when we click on it shushi and bbq and navigate to that section?
something like this :
$([some id]).animate({scrollTop: $elem.height()}, 800);
in one page, if we have html like this
and we click on tag it will navigate to particular section, that's fine
<a href="#shushi">Sushi</a>
<a href="#bbq">BBQ</a>
Sample Page:
<div id='sushi'></div>
<div id='bbq'></div>
but is it possible to add some animation effect when we click on it shushi and bbq and navigate to that section?
something like this :
$([some id]).animate({scrollTop: $elem.height()}, 800);
Share
Improve this question
edited Jun 3, 2014 at 17:13
vir
asked Jun 3, 2014 at 17:07
virvir
551 silver badge6 bronze badges
3 Answers
Reset to default 2Working DEMO
$(document).on("click","a",function(e){
e.preventDefault();
var id = $(this).attr("href"),
topSpace = 30;
$('html, body').animate({
scrollTop: $(id).offset().top - topSpace
}, 800);
});
This should work:
$('html, body').animate({scrollTop: $elem.scrollTop()}, 800);
http://api.jquery./scrolltop/
In your stylesheet add this code it will work fine
html{scroll-behavior: smooth;}
本文标签: javascriptHow to navigate to a section of a page using animationStack Overflow
版权声明:本文标题:javascript - How to navigate to a section of a page using animation? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745401394a2657055.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论