//首先获取文档对象 var target; if(document.documentElement.scrollTop){ target=$("html"); }else{ target=$("body");}
//到某元素
$("#nu").on("click",function(e){ e.preventDefault(); var timer=setInterval(function () { var top=target.scrollTop(); if(top>=$("#introduce").offset().top-20){ clearInterval(timer); } target.scrollTop(top+=10); },20) });//到底部 $("#btn-up").on("click", function () { var timer=setInterval(function () { var iScrollTop=target.scrollTop(); if(iScrollTop>=$(document).height()-$(window).height() ){ clearInterval(timer); } target.scrollTop(iScrollTop+=50); },20); })
jquery中点击某元素后滚动条滚动到某元素位置或底部
最新推荐文章于 2026-04-08 18:11:36 发布
本文介绍如何使用jQuery实现点击事件后,浏览器滚动条滚动到特定元素的位置,或者直接滚动到页面底部。通过示例代码,详细解析这一功能的实现方法。

6761

被折叠的 条评论
为什么被折叠?



