2011-12-14 13 views
2

私は心が失われていますが、これは簡単ではないと思うので、jQueryのnoobのように複雑になりました。一口。tab( 'select'、#)の後にスクロールしないscrollTo()

このページでは#switchto = ac#goto = acemergencyハッシュタグを使用し、jQueryのタブを適切に切り替えた後、目的のIDにスクロールすることになっています。問題は、tabs()が自動的にコンテナの先頭にスクロールし、scrollTo()が呼び出されたときにスクロールする場所がわからなくなることです。つまり、スクロールしません。ここ

jQuery(window).hashchange(function(e) { 
    if (window.location.hash) { 
     var hash = window.location.hash.substring(1); //Puts hash in variable, and removes the # character 
     var instruct = hash.split('#'); //split instructions 
     var whichtab = instruct[0].split('='); // split instruction from tab name 

     try { 
      var whichid = instruct[1].split('='); // split instruction from id name 
     } 
     catch (err) { /*suppress*/ 
     } 

     if (whichtab[0] == "switchto") { 
      switch (whichtab[1]) { 
       case 'ac': 
        try { 
         if (whichid[1] != "") { 
          $s.when(targettab(0)).then(targetid(whichid[1])); 
         } 
        } catch (err) {} 
        $s('.tour').tabs('select', 0); 
        break; 
       case 'heating': 
        try { 
         if (whichid[1] != "") { 
          $s.when(targettab(1)).then(targetid(whichid[1])); 
         } 
        } catch (err) {} 
        $s('.tour').tabs('select', 1); 
        break; 
       case 'plumbing': 
        try { 
         if (whichid[1] != "") { 
          $s.when(targettab(2)).then(targetid(whichid[1])); 
         } 
        } catch (err) {} 
        $s('.tour').tabs('select', 2); 
        break; 
      } 
     } 
    } 
}); 

とのMy機能::私はいくつかの方法を試してみました

function targetid(givenid) { 
    //$s('html,body').animate({scrollTop: $s("#"+givenid).offset().top},'fast'); 
    $s.scrollTo($s("#" + givenid), 400); 
    $s("#" + givenid).delay(500).fadeTo('slow', 0.1, function() { 
     $s("#" + givenid).fadeTo('slow', 1); 
     console.log('got ' + givenid + ' and scrolled to it'); 
    }); 
} 

function targettab(giventab) { 
    $s('.tour').tabs('select', giventab); 
} 

私はここstackoverflowの上発見しましたが、それらのどれも私の問題を修正するようだ

は、ここに私のイベントハンドラです。何か案は? tabs()がtabsselectの上にスクロールバックするのを止める方法はありますか?

答えて

0

私は本当にあなたのコードでそれほど熱心に見えませんでしたが、実際にscrollTopを意味するのではなく、scrollToを意味しませんか?

$s("#" + givenid).scrollTop(400); 

また、これは$ S(「#」+ givenidは)あなたがスクロールするコンテナのための正しい選択であることを前提としています$ sに仮定すると、あなたのjQueryオブジェクト、あなたがしようとすると何が起こるかです。

私はここにいることができました(再び、それほど難しくはありませんでした)が、助けてくれることを願っています!

関連する問題