【发布时间】:2013-04-18 07:58:23
【问题描述】:
我尝试使用历史 API 制作菜单。但在我看来,它的效果并不好,我有理由这么认为:
1 我的“头衔”没有改变
2 如果我在链接上点击快速,我会在页面重新加载时闪烁,但它不应该!(但如果我点击慢速也没关系。如何防止重新加载或闪烁?)
请告诉我我做错了什么
$(document).ready(function(){
sliderStartUp()
//menu click
$('.navigation').click(function(){
//fill the storage
var storage = {
url: $(this).children('a').attr('href'),
title: $(this).children('a').attr('title')
};
history.pushState(null, storage.title, storage.url );
$.ajax({
url: $(this).children('a').prop("href"),
cache: false,
success: function(data){ //if the data you return is a css notation (eg: #id) of the location of the title name
JqObj = $(data);
var addSmth = JqObj.find('#central').html();
$("#central").html('').html(addSmth);
sliderStartUp()
}
});
return false;
});
function sliderStartUp(){
$('#slider').nivoSlider({
effect: 'fold',
animSpeed: '500',
pauseTime: '4000'
});
}
});
这是我的生活
<ul id="navig">
<?php
if ($_SERVER['REQUEST_URI'] == "/")
{
$_SERVER['REQUEST_URI'] = "/index";
}
$arrayNav = array( array (
'name' => 'yyyyyy',
'title' => 'yyyyyyyyyyy',
'link' =>'http://bistro.loc/index',
'identificator' => 'id_index',
'pattern' => '/index/i'
),
array (
'name' => 'xxxxxx',
'title' => 'xxxxxxx',
'link' => http://bistro.loc/price',
'identificator' => 'id_price',
'pattern' => '/price/i'
),
array (
'name' => 'aaa',
'title' => '',
'link' => 'http://bistro.loc/#' ,
'identificator' => 'id_serv',
'pattern' => '/#/i'
),
array (
'name' => 'ssss',
'title' => '',
'link' => 'http://bistro.loc/#' ,
'identificator' => 'id_cont',
'pattern' => '/#/i'
),
array (
'name' => 'dddd',
'title' => '',
'link' => 'http://bistro.loc/#' ,
'identificator' => 'id_about',
'pattern' => '/#/i'
));
foreach ($arrayNav as $item)
{if (preg_match($item['pattern'],"http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] ))
{
echo "<li class = \"navigation\" id = \"".$item['identificator']."\" tltle=\"".$item['title']."\"><a href=\"".$item['link']."\" class=\"active\">".$item['name']."</a></li>";
}else{
echo "<li class = \"navigation\" id = \"".$item['identificator']."\" tltle=\"".$item['title']."\"><a href=\"".$item['link']."\">".$item['name']."</a></li>";}
;}
?>
</ul>
【问题讨论】:
-
ajax函数获取什么数据?
-
只是一个 [div #central]。只有html。
-
我的意思是
url: $(this).children('a').prop("href")返回什么? -
现在当然可以在您的帮助下正常工作。但我有一个时刻,我首先尝试自己做。非常感谢(我不能投票,因为我的代表
-
我可以帮助你,但我没有看到你所有的代码(我没有看到你的 javascript 返回),我建议考虑简单可用的功能(接口),如:
goBackInHistory()、@987654325 @ 等。这将使您的代码更易于阅读、理解和调试;)。
标签: javascript jquery ajax history