我有一个链接按钮,可以转到另一个页面,它可以工作,但我希望链接转到该页面的特定部分。我知道我应该为此使用 jquery,并且由于某种原因它不会跳转到我希望它跳转到的部分。
我的按钮链接:
<div class="btn_holder top-slide"><a
href="http://testurl.com/media#isabelo"><p class="leeu_button">READ
MORE</p></a>
</div>
我目前的内容滚动到页面底部,而不是滚动到 id="isabelo"的部分。所以这个 jquery 可以工作,但它不是我想要的。希望您能理解。
$(document).ready(function(){
//check if hash tag exists in the URL
if(window.location.hash) {
$("html, body").animate({ scrollTop: $(document).height() }, 1000);
1000);
} });
我也已经尝试过这个(根本不起作用):
$(document).ready(function(){
//check if hash tag exists in the URL
if(window.location.hash) {
$('html, body').animate({ scrollTop: $("#isabelo").offset().top }, 1000);
}
});
我尝试链接到的页面有一个 id="isabelo"的 div
<div class="content_holder terms_row" id="isabelo">
最佳答案
<a href="http://www.example.com/some-page-or-other.html#exactline">Click here</a>
你想要跳转到的位置应该有name="exactline"
属性
关于javascript - 将按钮链接到另一个页面的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37049868/