我希望使用html和jQuery实现标题之间的平滑滚动效果。通过按下“下一个”按钮,用户将移动到最接近的下一个标题。
简化后的代码如下:
我尝试使用下面的jQuery代码,但它无法工作:
简化后的代码如下:
<div class="article-content">
<div class="title">
<a href="#" id="next">next</a>
<h2>Title1</h2>
</div>
some text goes here
<div class="title">
<a href="#" id="next">next</a>
<h2>Title2</h2>
</div>
<div class="title">
<a href="#" id="next">next</a>
<h2>Title3</h2>
</div>
</div>
我尝试使用下面的jQuery代码,但它无法工作:
$("#next").click(function() {
var next;
next = $(this).parent().next().find(".title");
$('html,body').animate({ scrollTop: next.offset().top
}, 1000);
});
data-id
或class
来区分您的“下一个”链接。 - Austin Mullins