我想使用.fadeIn()使我的动态内容交换看起来更加流畅。但是我得到的是一种我只能描述为双重淡入淡出(淡入、淡出,然后再次淡入)。 我对JS和jQuery API都是新手,所以任何帮助都会感激。 演示页面:http://robert-richter.com/boilerplate/
此外,window.location.hash会在类似于
$('nav a').click(function(e) {
e.preventDefault()
var href = "inc/" + this.href.split('=').pop() + ".php"
$('.con').hide().load(href).fadeIn;
if (href == 'inc/blog.php') {
document.title = 'Robert-Richter.com | Blog';
window.location.hash = 'index.php?content=blog';
} else if (href == 'inc/portfolio.php') {
document.title = 'Robert-Richter.com | Portfolio';
window.location.hash = 'index.php?content=portfolio';
} else if (href == 'inc/lebenslauf.php') {
document.title = 'Robert-Richter.com | Lebenslauf';
window.location.hash = 'index.php?content=lebenslauf';
} else if (href == 'inc/kontakt.php') {
document.title = 'Robert-Richter.com | Kontakt';
window.location.hash = 'index.php?content=kontakt';
} else {
document.title = 'Robert-Richter.com';
window.location.hash = '';
}
return false;
});
此外,window.location.hash会在类似于
domain/boilerplate/#index.php?content=blog
的位置添加一个#。
$('.con').hide().load(href).fadeIn();
- jcubic#
被称为“哈希”,因此window.location.hash
定义了URL中跟随哈希后面的字符串。 - cfsswitch
而不是这么多的if else
语句。 - putvande