简体   繁体   English

跳转链接在我的网站上不起作用

[英]Jump Links not working on my Website

For my website, I have a one page system as the index to showcase several different parts of my portfolio. 对于我的网站,我有一个页面系统作为索引,以展示我的投资组合的不同部分。 In my designs section I have categories that visitors can click on which will take them to another page. 在我的设计部分中,我提供了一些类别,访问者可以单击它们,然后将它们转到另一个页面。 On that page I have a "back" button when they click, it should take them back to the index and scroll down to the designs area so that they don't have to scroll down again to look at another section. 在该页面上,单击它们时我有一个“后退”按钮,应该将它们带回到索引并向下滚动到设计区域,这样它们就不必再次向下滚动来查看另一部分。

Right now I have <a id="designs"></a> just above the div that I have my design category in. 现在,我在设计类别所在的div上方有<a id="designs"></a>

On the category page that has the "back" button, the link is my URL with index.html#designs 在具有“后退”按钮的类别页面上,链接是我的URL,带有index.html#designs

Maybe I am doing this wrong but when I reload the page, it goes to the position I want for like a milisecond, and then it scrolls to the top. 也许我做错了,但是当我重新加载页面时,它会像毫秒一样转到我想要的位置,然后滚动到顶部。

Is there any way to make it so that it will not scroll to the top of the page? 有什么方法可以使其不会滚动到页面顶部吗? I don't want it to be a challenge for people to view my portfolio. 我不希望它成为人们查看我的作品集的挑战。

Thanks so much! 非常感谢!

Try to use e.preventDefault() : 尝试使用e.preventDefault()

$('#designs').click(function(e) {
     e.preventDefault();
});

This selector only target the #designs anchor. 该选择器仅定位于#designs锚点。 You can give all of your expected anchors a common class such as class="anchors" then you can do: 您可以为所有预期的锚定一个通用类,例如class="anchors"然后可以执行以下操作:

$('.anchors').click(function(e) {
     e.preventDefault();
});  

You need to change your html like, 您需要像这样更改html,

<!-- add href like #designs -->
<a href="#designs">Design</a>

<!-- div design having id designs which you want to show on top -->
<div id="designs">Design div</div>

Demo 演示版

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

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