jquery中点击某元素后滚动条滚动到某元素位置或底部

来源:互联网 发布:云安全软件好用吗 编辑:程序博客网 时间:2024/05/25 05:35
//首先获取文档对象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);})

阅读全文
0 0
原创粉丝点击