gpt4 book ai didi

javascript - 如何使用 jQuery 自动滚动到另一个页面

转载 作者:行者123 更新时间:2023-12-01 02:31:58 27 4
gpt4 key购买 nike

我在索引和配置文件中有两个文件。我想通过自动滚动转到个人资料页面并直接转到常见问题解答部分

我的索引

<a href="profile.html">Go</a>

我的个人资料

<section id="home" style="height:500px;background:red">
<section id="name" style="height:500px;background:yellow">
<section id="faq" style="height:500px">

我可以从主页直接点击个人资料页面中的 id="faq"吗?谢谢

最佳答案

是的,你可以这样做:

首先在 anchor 标记中指定一个名称,类似于您想要滚动的首选位置的 profile.html 页面中的名称:

<a name="jumpHere">somewhere</a>

然后设置链接位置,如下所示:

<a href="profile.html#jumpHere">Go</a>

现在单击预期的元素,您可以触发顶部链接或编写如下内容:

$("#faq").click(function(){
window.location = 'profile.html#jumpHere';
})

关于javascript - 如何使用 jQuery 自动滚动到另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48249261/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com