gpt4 book ai didi

JavaScript anchor 导航

转载 作者:行者123 更新时间:2023-11-30 23:49:07 28 4
gpt4 key购买 nike

我正在创建一个带有“ anchor 导航”的网站,就像 Facebook 和谷歌邮件一样。我已经让它工作了,但还不完全。当我加载带有 #contact 之类的页面时,除非我单击它的链接,否则它不会加载它。另外,是否有更好、更有效的方法来完成我正在做的事情?我不是 JS 编程方面最好的人。

JavaScript:

$.navigate = function() {
// a new link
if($anchor != document.location.hash){
// add a preloader
$("#content")
.empty()
.html('<p class="align-center"><img src="assets/images/loading.gif" /></p>');
// change the anchor saved for next time
$anchor = document.location.hash;
// get the variables ready for the get
var i = $anchor.substring(1).split("/");
var $page = i[0];
var $y = (i[1]) ? i[1] : false;
// get the file
$.get("callback.php", { x: $page, y: $y }, function(data){
$("#content")
.empty()
.html(data);
},"html");
}
};

$(function() {

var $anchor = "";
// change from the URI. This dont work.
if(document.location.hash){ $.navigate(); }

$("a","#nav")
.css({backgroundColor:"#f7f7f7"})
.each(function() {
$(this).attr("href","#" + $(this).attr("name"));
});

setInterval('$.navigate()', 300);

});

HTML:

<div id="nav">  
<ul class="horizontal-nav">
<li><a href="http://streetmafia.co.uk/" name="index">Home</a></li>
<li><a href="http://streetmafia.co.uk/about" name="about">About</a></li>
<li><a href="http://streetmafia.co.uk/portfolio" name="portfolio">Portfolio</a></li>
<li><a href="http://streetmafia.co.uk/contact" name="contact">Contact</a></li>
</ul>
<div id="l-nav"></div>
<div id="r-nav"></div>
</div>

最佳答案

尝试ReallysimpleHistory jquery 插件。

关于JavaScript anchor 导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1942013/

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