html中页面跳转到指定位置的三种方式
$("#sl").on('tap', function(e) {
//方式一
window.location.hash="#sucaiLocal"; //点击后地址栏url会在原来url后边加上#bottombox,再次点击没有反应
//方式二
var bottombox = document.getElementById("sucaiLocal");
bottombox.scrollIntoView(); //点击后地址栏url不会变化,可多次点击
//方式三
$("html, body").animate({ //点击后地址栏url会在原来url后边加上#bottombox,再次点击没有反应
scrollTop: $("#sucaiLocal").offset().top
}, {
duration: 500,easing: "swing"
});
return false;
});点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号