我已经浏览了很多论坛,讨论我的大脑试图获得这个超级简单的加载函数的工作。我已经将其缩小到我认为loadContent
函数的.fadeIn()
部分中的选择器问题。Ajax调用加载当前内容
我可以看到它为什么会一直加载相同的东西,因为它使用相同的选择器,但基于我一直试图使用的教程(http://css-tricks.com/rethinking-dynamic-page-replacing-content/)以及其他(甚至更多破碎)方法,我DID开始工作(基于此:http://code.tutsplus.com/tutorials/how-to-load-in-and-animate-content-with-jquery--net-26),它似乎应该工作!
我试过使用$(href)
作为选择器,但它只是淡化旧内容并且不加载任何内容。我也试着添加一个alert来查看href是什么,然后返回正确的html页面,然后返回正确的元素id(Articles/Cats.html #content)。
这里是函数本身,如果你需要更多的信息,我会很高兴给它!任何帮助都会令人难以置信,很好,很有帮助!
function articleClickLoad() {
if (Modernizr.history) {
var newHash = "",
$Content = $("#content"),
$el;
$("#content").on("click", "a", function() {
var _link = $(this).attr("href");
var toLoad = $(this).attr('href')+' #content';
history.pushState(null, null, _link);
loadContent(toLoad);
return false;
});
function loadContent(href){
$Content.find("#content");
$Content.fadeOut(1000, function() {
$("main").load(href,'', function() {
$Content.fadeIn(1000);
});
});
}
$(window).bind('popstate', function(){
_link = location.pathname.replace(/^.*[\\\/]/, ''); //get filename only
loadContent(toLoad);
});
}
}
articleClickLoad();
谢谢!
您并未从任何位置加载任何新数据,因此您希望新数据来自哪里? – orhanhenrik 2014-10-28 21:29:26
@Izzey'$(“main”)。load(...)'不加载数据? – 2014-10-28 21:33:46
好.load正在调用href,这是新的页面内容,但我真的不知道如何使内容淡入淡出 – mconway116 2014-10-28 21:33:57