我正在开发一个单页投资组合网站,该网站将从单独的 html 文件中提取项目。所以,目前我有这段代码将新的 URL(特别是#project
div)加载到当前的 div#port-content
中。
我的 custom.js 的一部分如下:
var hash = window.location.hash.substr(1);
var href = $('.ajax').each(function(){
var href = $(this).attr('href');
if(hash==href.substr(0,href.length-5)){
var toLoad = hash+'.html #project';
$('#port-content').load(toLoad)
}
});
$('a.port-more').click(function(){
var toLoad = $(this).attr('href')+' #project';
$('#port-content').hide('normal',loadContent);
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
function loadContent() {
$('#port-content').load(toLoad,'',showNewContent())
}
function showNewContent() {
$('#port-content').show('normal');
}
return false;
});
如何关闭此内容并恢复我原来的#port-content
div。我试图创建一个相反的新功能,但没有奏效。
有任何想法吗?