0

うまく機能するカスタムjQueryタブ(UIではない)があります。ただし、タブはを使用するためfadeIn()、別のタブをクリックすると、ページの上部にジャンプします。

これらの2つの解決策(以下)を確認しましたが、高さを設定することでジャンプの問題は解決するようです。ただし、高さを静的に設定したくありません。高さを動的に設定しようとしましたが、何らかの理由で機能しません。コンテンツ()も読み込もうとしましload()たが、動作させることもできません。

jQueryフェードによるページジャンプ

新しい画像の読み込み中にクリックジャンプしたJQueryのfadeIn/fadeOut画像

私のHTMLコードはこれです:

<ul class="port-tabs">
<li><a href="#tab1">Web Design &amp; Dev</a></li>
<li><a href="#tab2">Graphic Design</a></li>
<li><a href="#tab3">Photography</a></li>
</ul>

<div class="port-slides slides-list tab-container">
<div id="tab1" class="port-subpages tab-content">
    <ul class="portfolio">
  <li>
<div id="port-window">
    <span class="window"></span>
    <span class="gradient"></span>
    <a href="#"><img src="http://localhost:8888/wordpress/wp-content/uploads/2012/07/port-image1.jpg" alt="" title="" width="223" height="225" class="alignnone size-full wp-image-112" /></a>
</div>
  </li>
  <li>
<div id="port-window">
    <span class="window"></span>
    <span class="gradient"></span>
    <a href="#"><img src="http://localhost:8888/wordpress/wp-content/uploads/2012/07/port-image2.jpg" alt="" title="" width="223" height="225" class="alignnone size-full wp-image-112" /></a>
</div>
  </li>
  <li>
<div id="port-window">
    <span class="window"></span>
    <span class="gradient"></span>
    <a href="#"><img src="http://localhost:8888/wordpress/wp-content/uploads/2012/07/port-image3.jpg" alt="" title="" width="223" height="225" class="alignnone size-full wp-image-112" /></a>
</div>
  </li>

  <li>
<div id="port-window">
    <span class="window"></span>
    <span class="gradient"></span>
    <a href="#"><span class="port-just-text">TEXT PLACEHOLDER 1</span></a>
</div>
  </li>
  <li>
<div id="port-window">
    <span class="window"></span>
    <span class="gradient"></span>
    <a href="#"><span class="port-just-text">TEXT PLACEHOLDER 2</a>
</div>
  </li>
  <li>
<div id="port-window">
    <span class="window"></span>
    <span class="gradient"></span>
    <a href="#"><span class="port-just-text">TEXT PLACEHOLDER 3</a>
</div>
  </li>
</ul>
</div>
<p class="clearBoth"></p> <!-- Temporary fix: remove when live -->
<div id="tab3" class="port-subpages tab-content">
    <p>Tab Content 3</p>
</div>

jQueryコードは次のとおりです。

$(document).ready(function() {

    //When page loads...
    $(".tab-content").hide(); //Hide all content
    $("ul.port-tabs li:first").addClass("active").show(); //Activate first tab
    $(".tab-content:first").show(); //Show first tab content


    //On Click Event
    $("ul.port-tabs li").click(function() {

        $("ul.port-tabs li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab-content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        //activeHeight = $(activeTab).height();
        //alert(activeHeight);
        $(activeTab).fadeIn(); //Fade in the active ID content
        return false;
    });
});

誰かが新しいタブをクリックしたときに一番上にジャンプするのをなくすのを手伝ってもらえますか?

4

1 に答える 1

0

これは、アンカー タグが原因で発生していると思います。これらの行を追加してみてください

  $("ul.port-tabs li").click(function(e) {
  e.preventDefault();
  e.stopPropagation();
于 2012-08-01T01:32:51.623 に答える