var position = $(".element").offset(); position.top = position.top-60; $("html,body").animate({scrollTop:position.top}, 100);
首先获取某元素的位置
第二部 top 就是元素在纵轴的位置 可以自己进行调整 这里选择元素位置向上60px 就是-60
第三步滚动到指定位置 第二个参数为滚动时间 单位毫秒
var position = $(".element").offset(); position.top = position.top-60; $("html,body").animate({scrollTop:position.top}, 100);
首先获取某元素的位置
第二部 top 就是元素在纵轴的位置 可以自己进行调整 这里选择元素位置向上60px 就是-60
第三步滚动到指定位置 第二个参数为滚动时间 单位毫秒
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。