//首先获取文档对象 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中点击某元素后滚动条滚动到某元素位置或底部
最新推荐文章于 2025-06-11 13:53:21 发布