繁体   English   中英

跳转链接不起作用

[英]Jump links are not working

我正在使用wordpress,并对跳转菜单链接使用了简单的逻辑,如下所示:

一个示例如下所示:

<div id="whatever-you-want-to-call-it">
    The content of your div here.
</div>

2)链接到锚点目标要链接到锚点,只需使用:

<a href="#whatever-you-want-to-call-it">Link Text Here</a>

或在另一页上:

  <a href="pagename.html#whatever-you-want-to-call-it">Link Text Here</a>

但是它不能在另一个页面上工作。对于同一页面,它已经完成,但是当我从另一个页面单击时,它仅加载该页面,而不使用id加载该特定部分。

这是您可以尝试的示例。

将其另存为桌面上的普通test.html,然后使用浏览器将其打开。

然后在URL末尾添加#get-me并重新加载页面。

我的网址看起来像这个file:///Users/ipeak/Desktop/test.html#get-me

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>animate demo</title>
<style>
.big-height {
    width:100%;
    background-color:orange;
    height:1000px;
    margin:20px;
}
#get-me {
    background-color:blue;
    margin:20px;height:500px;
    width:100%;
}
</style>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
    <a href="#get-me">click here</a>
    <div class="big-height"></div>
    <div id="get-me"><div>

<script>
$(window).load(function(){

    //alert(window.location.hash);
    $("html,body").animate({
        scrollTop: $(window.location.hash).offset().top
    },900);
});

</script>
</body>
</html>

我们在这里等待的是页面加载完毕。 然后通过jQuery检查给定hash元素的位置,并为其设置动画。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM