0

我在这里有一个页面。

http://www.kharota.com/cantsay/index.html

我想要的是随着 url 的变化上下滑动 div 例如 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

4

1 回答 1

0
$(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"); 
        }
    });
});

我无法测试它,但我希望这对你有用

于 2012-08-07T06:06:14.813 回答