Tay*_*Mac 2 javascript jquery scroll jquery-selectors jquery-scrollable
只是想知道是否有可能在页面上滚动到某个div的位置onclick.我似乎无法在互联网上找到任何记录在案的地方.
我的想法是单击一个按钮,它将带您到页面上该div的位置,可能是div ID.
问候,
泰勒
我不确定你什么时候想要举办活动,所以这里是通用版
$(selector).click(function() {
//scroll to div
});
Run Code Online (Sandbox Code Playgroud)
如果你想要一个<button/>带有id的myButton,当你点击它会导致你滚动到一个<div/>with和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);
});
Run Code Online (Sandbox Code Playgroud)
使用jQuery ScrollTo插件.