只是想知道是否可以在单击时滚动到页面上的某个 div 位置。我似乎无法在互联网上找到任何记录此内容的地方。
我的想法是单击一个按钮,它会将您带到页面上该 div 的位置(可能通过 div ID 来实现)。
问候,
泰勒
最佳答案
我不确定您希望事件何时触发,所以这是通用版本
$(selector).click(function() {
//scroll to div
});
如果你想要 <button/>
ID 为myButton
单击时将导致您滚动到 <div/>
其 ID 为 myDiv
半秒内:
$('#myButton').click(function() {
//optionally remove the 500 (which is time in milliseconds) of the
//scrolling animation to remove the animation and make it instant
$.scrollTo($('#myDiv'), 500);
});
使用 jQuery ScrollTo插件。
关于jquery - jquery滚动问题。如何自动滚动 onclick 到 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5903614/