简体   繁体   English

带有跳转链接的网页

[英]Webpages with jump links

I am new in the world of web development so excuse my ignorance in some points :p 我是Web开发领域的新手,请原谅我在某些方面的无知:p

Anyone can tell how jump links work? 任何人都可以告诉跳转链接如何工作? And how to implement them? 以及如何实施它们?

Let me make a specific example, I want to create a website with an horizontal bar, I saw some modern sites that those links doesn't change the page, they just jump down to another section and if I scroll up, I end up on home again. 让我举一个具体的例子,我想创建一个带有单杠的网站,我看到一些现代网站,这些链接不会更改页面,它们只是跳到另一部分,如果我向上滚动,最终又回到家。

How can I implement this and does it work with bootstap? 如何实现此功能,并与Bootsap一起使用?

Thanks 谢谢

That, my friend, is a single page website, they are not jump links, you are only using jquery to scroll down to the content on click. 我的朋友,那是一个单页网站,它们不是跳转链接,您仅使用jquery向下滚动到单击的内容。

Here is an example of a code that will do just that : 这是将执行此操作的代码示例:

$(function() {
    $("#abc").bind("click", function() {
        $("html, body").animate({
            scrollTop: $("#anchor").offset().top
        }, 500);
    });
})(jQuery);

When you click on an element with an id of abc it will take you to the top of the #anchor id element, no matter where on the page it is found. 单击ID为abc的元素时,无论在页面上的什么位置,它都将带您到#anchor id元素的顶部。

Also, here is an example using this exact code : jsfiddle 另外,这是一个使用此确切代码的示例: jsfiddle

<a href="#title1">Go to title1</a>
<a href="#title2">Go to title2</a>


/* Lots of space */

<a name="title1">Title 1</a>

/* Lots of space */

<a name="title2">Title 2</a>

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

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