简体   繁体   English

带有锚定到另一个页面和 ID 的菜单不起作用

[英]Menu with Anchor to another page and ID does not work

i'm facing this strange problem for the first time.我第一次面对这个奇怪的问题。 Probably is something really easy but i can't get out.可能真的很容易,但我无法出去。

If you open the menu in this page: https://danielepinazzi.com/fabric/如果您打开此页面中的菜单: https : //danielepinazzi.com/fabric/

and you try to navigate into that page with anchor link, it works perfectly.并且您尝试使用锚链接导航到该页面,它运行良好。

If you open the "contact us" page and then try to click on another link in the menu, like "what we do" it will close the menu and do nothing.如果您打开“联系我们”页面,然后尝试单击菜单中的另一个链接,例如“我们做什么”,它将关闭菜单并且什么也不做。 But if you try to right click and select "open in a new tab", it work.但是,如果您尝试右键单击并选择“在新选项卡中打开”,它会起作用。

Edit because i need to explain better: I've already added the absolute link in the menu, not only the anchor.编辑,因为我需要更好地解释:我已经在菜单中添加了绝对链接,而不仅仅是锚点。 The section #whatwedo is linked with https://danielepinazzi.com/fabric/#whatwedo #whatwedo 部分与https://danielepinazzi.com/fabric/#whatwedo链接

I'm using Chrome on a Mac.我在 Mac 上使用 Chrome。

Can someone explain this to me?谁可以给我解释一下这个?

Thank you and have a nice day you all.谢谢大家,祝大家有个美好的一天。

You have probably added anchor links via the menu like #link .您可能已经通过#link菜单添加了锚链接。 Those links only work if you are on the page where these anchors are placed.只有当您位于放置这些锚点的页面上时,这些链接才有效。 If you want them to work when you are on another page, you should add them as /fabric/#link since the homepage for your project is /fabric/ .如果你想让它们在你在另一个页面上工作,你应该将它们添加为/fabric/#link因为你项目的主页是/fabric/

Note: it is easiest if you use absolute URL's in your menu (ie https://danielepinazzi.com/fabric/#whatwedo instead of just #whatwedo . Don't forget to update those if you migrate to a production environment.注意:如果您在菜单中使用绝对 URL,这是最简单的(即https://danielepinazzi.com/fabric/#whatwedo而不是#whatwedo 。如果您迁移到生产环境,请不要忘记更新这些。

I inspected whats going on there, you have a code block as mentioned below;我检查了那里发生了什么,你有一个如下所述的代码块;

When i do what you said on the problem, isSamePage returns true because you are splitting anchor tag on href variable当我按照您在问题上所说的进行操作时,isSamePage 返回 true,因为您正在拆分 href 变量上的锚标记

$this.attr("href").split("#")[0]

and it returns https://danielepinazzi.com/fabric/ which is already in url.它返回已经在 url 中的https://danielepinazzi.com/fabric/

That makes isSamePage true according the code and prevents the action.根据代码,这使得 isSamePage 为真并阻止了该操作。

    $(".mk-fullscreen-nav-close, .mk-fullscreen-nav-wrapper, #fullscreen-navigation a").on("click", function(e) {
        $(".mk-fullscreen-nav").removeClass("opened"),
        $(".mk-dashboard-trigger").removeClass("fullscreen-active"),
        $("body").removeClass("fullscreen-nav-opened");
        var anchor = MK.utils.detectAnchor(this)
          , $this = $(this)
          , href = $this.attr("href").split("#")[0]
          , url = window.location.href
          , isSamePage = -1 !== url.indexOf(href);
        anchor.length ? (isSamePage && e.preventDefault(),
        MK.utils.scrollToAnchor(anchor)) : "#" === $this.attr("href") && e.preventDefault()
    })

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

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