我正在开发一个网页组合的网站,这将拉动项目从单独的HTML文件。所以,现在我有这个code加载新的URL(特别是 #project
DIV)到当前分区#端口含量
。
I'm developing a one page portfolio site which will pull projects from separate html files. So, currently I have this code that loads the new URL (specifically the #project
div) into the current 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;
});
我如何关闭这个内容,并带回我原来的#端口含量
DIV。我试图创建一个新的功能,做相反的,但没有奏效。
How can I close this content and bring back my original #port-content
div. I tried to create a new function doing the opposite but it didn't work.
任何想法?
使用的.data()
听起来像是正确的选项这一点。
Using .data()
sound like the correct option for this.
function loadContent() {
if(!$('#port-content').data('default')) $("#port-content").data('default', $("#port-content").html());
$('#port-content').load(toLoad,'',showNewContent())
}
// and create another function to load the default
function loadDefault() {
$('#port-content').html($("port-content").data('default'));
}