我在这里有一个页面。
http://www.kharota.com/cantsay/index.html
我想要的是随着url的变化而上下滑动,例如,index.html#thisweek将滑动包含本周数据的div。它有时起作用,有时不起作用。我很困惑,没有错误,但仍然不能工作。代码如下
var loc = window.location.href;
if(loc.indexOf( '#' ) >= 0 ) {
var hash = loc.substr( loc.indexOf('#') + 1 );
}else{
var hash = "";
}
if(!hash){
$("#ca").slideDown("fast");
}else{
switch(hash){
case "iwantagig":
$("#cd").slideDown("fast");
$("#ca").slideUp("fast");
$("#cb").slideUp("fast");
$("#cc").slideUp("fast");
break;
case "jointhecrew":
$("#cc").slideDown("fast");
$("#ca").slideUp("fast");
$("#cb").slideUp("fast");
$("#cd").slideUp("fast");
break;
case "birthdayGuestlist":
$("#cb").slideDown("fast");
$("#ca").slideUp("fast");
$("#cc").slideUp("fast");
$("#cd").slideUp("fast");
break;
case "thisweek":
$("#ca").slideDown("fast");
$("#cb").slideUp("fast");
$("#cc").slideUp("fast");
$("#cd").slideUp("fast");
break;
}
}页面在这里。如果有人能帮忙,我会很感激的。
http://www.kharota.com/cantsay/index.html
发布于 2012-08-07 14:06:15
$(document).ready(function(){
$('a.change-page').click(function(){
var hash = window.location.hash.substring(1);
if(hash) {
$('.slider').slideUp("fast");
$('.' + hash).slideDown("fast");
// where '.' + hash are your page divs which must have the class slider and classes like jointhecrew, iwantgag etc
} else {
$("#ca").slideDown("fast");
}
});
});我不能测试它,但我希望它能为你工作
https://stackoverflow.com/questions/11840050
复制相似问题