单击时平滑滚动到特定div [英] Smooth scroll to specific div on click
本文介绍了单击时平滑滚动到特定div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要做的就是这样做,如果你点击一个按钮,它会向下滚动(平滑)到页面上的特定div。
What I'm trying to do is make it so that if you click on a button, it scrolls down (smoothly) to a specific div on the page.
我在这里开始了一个JSFiddle: http://jsfiddle.net/ryXFt/2/
I've started a JSFiddle here: http://jsfiddle.net/ryXFt/2/
我需要的是,如果你点击按钮,它会平滑滚动到div'second'。
What I need is if you click on the button, it smooth scrolls to the div 'second'.
HTML:
<div class="first"><button type="button">Click Me!</button></div>
<div class="second">Hi</div>
CSS:
.first {
width: 100%;
height: 1000px;
background: #ccc;
}
.second {
width: 100%;
height: 1000px;
background: #999;
}
请帮忙。
推荐答案
执行:
$("button").click(function() {
$('html,body').animate({
scrollTop: $(".second").offset().top},
'slow');
});
更新了 Jsfiddle
这篇关于单击时平滑滚动到特定div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文