Ajax 选项卡淡入淡出效果问题 - jQuery 工具

发布于 2024-11-29 22:13:48 字数 2359 浏览 1 评论 0原文

使用 jQuery 工具库时,我无法使具有淡入淡出效果的 Ajax 选项卡正常工作。它只显示 ajax 调用的第一个项目的效果,但没有其他内容。

您可以在 www.excellenthost(dot)com/beta/test.php 看到测试 URL 或看到下面的代码:

JS:

<script type="text/javascript">
$(document).ready(function(){
        $("ul.features-tabs").tabs(".features-panes > div.features", {
        effect: 'fade',
        history: true,
        onBeforeClick: function(event, i) {
            loaddetails(this.getTabs().eq(i).attr("id"));
    function loaddetails(type) { var query = "details=" + type; 
    $.post("shared/details.php", query , function( data ) {
     $(".features").html(data); return false;}); return false;
   }; }});
   });
</script>

HTML:

   <div class="hostingFeatures-shadow"></div>
      <div class="hostingFeatures-bg">
      <div class="wrap"> 
          <ul class="features-tabs">
            <li><a id="core" href="#core">Core</a></li>
            <li><a id="email" href="#email">Email</a></li>

        </ul>

        <div class="features-panes">
            <ul class="packages-bar">
                <li class="features-title">&nbsp;</li>
                <li>1</li>
                <li>2</li>
                <li>3</li>
            </ul>

            <!-- First Slide -->
      <div class="features">
        </div>
    </div>
</div></div>

AJAX 内容: shared/details.php

<ul class="features-list"> 
 <? if($_POST['details']=='core'){ ?>
            <li class="features-name">Premium Disk Space</li>
                        <li>1000MB</li>
                        <li>2500MB</li>
                        <li>3500MB</li>
 <? } if($_POST['details']=='email'){ ?>
                       <li class="features-name">Email Accounts</li>
                        <li>35</li>
                        <li>45</li>
                        <li>65</li>
<? } ?>
</ul>

正如您从示例中看到的,单击“电子邮件”选项卡时不会加载任何内容。当我执行 debugalert(data); 时,Ajax 数据正确显示,因此抓取正确的数据没有问题。这只是将其发布到实际主页上的问题

有人可以帮忙吗? 布莱恩

I am unable to get the Ajax Tabs with a fade effect to work when using the jQuery Tools library. It only shows the effect for the first item called by the ajax, but nothing else.

You may see the test URL at www.excellenthost(dot)com/beta/test.php or see the code below:

JS:

<script type="text/javascript">
$(document).ready(function(){
        $("ul.features-tabs").tabs(".features-panes > div.features", {
        effect: 'fade',
        history: true,
        onBeforeClick: function(event, i) {
            loaddetails(this.getTabs().eq(i).attr("id"));
    function loaddetails(type) { var query = "details=" + type; 
    $.post("shared/details.php", query , function( data ) {
     $(".features").html(data); return false;}); return false;
   }; }});
   });
</script>

HTML:

   <div class="hostingFeatures-shadow"></div>
      <div class="hostingFeatures-bg">
      <div class="wrap"> 
          <ul class="features-tabs">
            <li><a id="core" href="#core">Core</a></li>
            <li><a id="email" href="#email">Email</a></li>

        </ul>

        <div class="features-panes">
            <ul class="packages-bar">
                <li class="features-title"> </li>
                <li>1</li>
                <li>2</li>
                <li>3</li>
            </ul>

            <!-- First Slide -->
      <div class="features">
        </div>
    </div>
</div></div>

AJAX Content:
shared/details.php

<ul class="features-list"> 
 <? if($_POST['details']=='core'){ ?>
            <li class="features-name">Premium Disk Space</li>
                        <li>1000MB</li>
                        <li>2500MB</li>
                        <li>3500MB</li>
 <? } if($_POST['details']=='email'){ ?>
                       <li class="features-name">Email Accounts</li>
                        <li>35</li>
                        <li>45</li>
                        <li>65</li>
<? } ?>
</ul>

As you can see from the sample, nothing loads when 'email' tab is clicked. When I do a debug alert(data);, the Ajax data appears properly, so there is no problem with grabbing the correct data. It is only a problem of getting it posted on the actual main page

Can someone please assist?
Brian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黑色毁心梦 2024-12-06 22:13:48

如果你真的想要“淡入淡出”效果,你可以这样做:

<ul class="features-tabs">
  <li><a href="/hosting/shared/details.php?details=core">Core</a></li>
  <li><a href="/hosting/shared/details.php?details=email">Email</a></li>
</ul>
(...)
<div class="features">
    <!-- Two divs to keep the content panes separated -->
    <div></div>
    <div></div>
</div>

并使用这个Javascript:

$("ul.features-tabs").tabs("div.features > div", {
  effect: 'fade',
  onBeforeClick: function(event, i) {
    var pane = this.getPanes().eq(i);
    if (pane.is(":empty")) {
      pane.load(this.getTabs().eq(i).attr("href"));
    }
  }
});

这应该可以!

If you really want the 'fade' effect, you can do this:

<ul class="features-tabs">
  <li><a href="/hosting/shared/details.php?details=core">Core</a></li>
  <li><a href="/hosting/shared/details.php?details=email">Email</a></li>
</ul>
(...)
<div class="features">
    <!-- Two divs to keep the content panes separated -->
    <div></div>
    <div></div>
</div>

And use this Javascript:

$("ul.features-tabs").tabs("div.features > div", {
  effect: 'fade',
  onBeforeClick: function(event, i) {
    var pane = this.getPanes().eq(i);
    if (pane.is(":empty")) {
      pane.load(this.getTabs().eq(i).attr("href"));
    }
  }
});

That should work!

深海少女心 2024-12-06 22:13:48

事实证明 jQuery Tools Tabs 解决方案不太适合这个,所以我为您制作了一个自定义脚本:

DEMO

$("ul.features-tabs").find('a').each(function(i) {

  $(this).click(function(event){
    event.preventDefault();
    var clickedPane = $("div.features > div").eq(i);
    if (clickedPane.is(':visible')) return;

    $(this).closest('ul').find('a').removeClass('current').end().end().addClass('current');

    if (clickedPane.hasClass('contentLoaded') || clickedPane.hasClass('contentLoading')) {
      clickedPane.siblings().fadeOut( function(){ clickedPane.fadeIn(); } );
    } else {
      clickedPane.addClass('contentLoading').load($(this).attr("href"),function(){
        $(this).removeClass('contentLoading').addClass('contentLoaded').siblings().fadeOut( function(){ clickedPane.fadeIn(); } );
      });
    }
  });

  // Load & show the initial tabbed pane
  if (i==0) $(this).click();
});

它完全取消了 jQuery 工具,并且完成了您需要的所有淡入淡出和 Ajax 加载。

为了使其工作,您需要稍微更改一下 HTML:

<div class="hostingFeatures-bg">
  <div class="wrap">

    <ul class="features-tabs">
      <li><a href="/hosting/shared/details.php?details=core">Core</a></li>
      <li><a href="/hosting/shared/details.php?details=email">Email</a></li>
    </ul>

    <div class="features-panes">
      <ul class="packages-bar">
        <li class="features-title"> </li>
        <li>ER-1</li>
        <li>ER-2</li>
        <li>ER-3</li>
      </ul>
      <div class="features">
        <div></div>
        <div></div>
      </div>
    </div>

  </div>
</div>

并对 CSS 进行添加:

<style type="text/css">
  .features > div { display: none; }
</style>

Turns out the jQuery Tools Tabs solution isn't very well suited for this, so I've made a custom script for you:

DEMO

$("ul.features-tabs").find('a').each(function(i) {

  $(this).click(function(event){
    event.preventDefault();
    var clickedPane = $("div.features > div").eq(i);
    if (clickedPane.is(':visible')) return;

    $(this).closest('ul').find('a').removeClass('current').end().end().addClass('current');

    if (clickedPane.hasClass('contentLoaded') || clickedPane.hasClass('contentLoading')) {
      clickedPane.siblings().fadeOut( function(){ clickedPane.fadeIn(); } );
    } else {
      clickedPane.addClass('contentLoading').load($(this).attr("href"),function(){
        $(this).removeClass('contentLoading').addClass('contentLoaded').siblings().fadeOut( function(){ clickedPane.fadeIn(); } );
      });
    }
  });

  // Load & show the initial tabbed pane
  if (i==0) $(this).click();
});

It does away with jQuery Tools entirely and it does all the fading and Ajax loading you need.

To make it work, you need to change the HTML a little:

<div class="hostingFeatures-bg">
  <div class="wrap">

    <ul class="features-tabs">
      <li><a href="/hosting/shared/details.php?details=core">Core</a></li>
      <li><a href="/hosting/shared/details.php?details=email">Email</a></li>
    </ul>

    <div class="features-panes">
      <ul class="packages-bar">
        <li class="features-title"> </li>
        <li>ER-1</li>
        <li>ER-2</li>
        <li>ER-3</li>
      </ul>
      <div class="features">
        <div></div>
        <div></div>
      </div>
    </div>

  </div>
</div>

And make one addition to your CSS:

<style type="text/css">
  .features > div { display: none; }
</style>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文