jquery - 在 .delay() 中嵌入函数无法正常工作

标签 jquery html css jquery-selectors

所以我有一个带有表格的 HTML,每列都有一个按钮,该按钮应该淡出该表格,然后淡入另一个 DIV,其中包含有关我单击的特定列的信息。所以 Jquery 看起来像这样:

  $(document).ready(function(){
    $('#motoBttn').bind('click', function(){
        $('#ServicesContent').fadeOut();
            $('#infoSlector').fadeIn();
            $('#motoDescContent').fadeIn();
            $('#goBackDiv').fadeIn() ;
    })
    $('#goBack').bind('click', function(){
        $('#infoSlector > div').fadeOut() ;
        $('#ServicesContent').fadeIn();
    })
  });

这个#goBack id 是一个按钮,每当我点击任何按钮时都会显示。并且会淡出任何刚刚淡入的东西。

这很好用,但这并不是我想要的。我碰巧在特定时间显示了两个 DIVS。所以你可以在衰落之间的某个点看到一个在另一个之上。

我发现延迟第一次褪色可以产生预期的效果。现在它看起来像这样:

$(document).ready(function(){
        $('#motoBttn').bind('click', function(){
            $('#ServicesContent').fadeOut().delay(800, function (){
                $('#infoSlector').fadeIn();
                $('#motoDescContent').fadeIn();
                $('#goBackDiv').fadeIn() ;

            });

        })

        $('#goBack').bind('click', function(){
            $('#infoSlector > div').fadeOut() ;
            $('#ServicesContent').fadeIn();
        })
      });

但是每当我单击“返回”按钮时,它都会自行淡出,但不会显示 DOM 上的第一个表。

这是 HTML 的样子:

<table id='ServicesContent'>
                <tr>
                    <td class='ServicesIcon'>
                         <img src="images/icon3.png" alt="" />

                    </td>
                </tr>
                <tr>
                    <td class='ServicesPreviewTitle'>
                        <h2>Venta de equipo motorola</h2>

                    </td>
                </tr>
                <tr>
                    <td class='ServicesPreviewContent'>
                        <p>Ceosdach es distribuidor autorizado Motorola. Tenemos todo en radiocomunicación.</p>
                    </td>
                <tr>
                    <td class='ServicesButton'>
                        <button class ="srvcViewBttn" id="motoBttn">Ver Oferta</button>

                    </td>
            </table>
                <div id="infoSlector"class="hidden" >
                    <div id="motoDescContent" class="hidden">
                        <div class= "wholewidhtcontent">
                            <h1>Venta de equipo motorola</h1>
                        </div>
                    </div>
                    <div id="goBackDiv" class="hidden">
                        <div class= "wholewidhtcontent">
                            <button class ="srvcViewBttn" id="goBack">Atrás</button>
                        </div>
                    </div>

                </div>

最佳答案

$.fn.delay不接受任何回调方法,因此您的代码不起作用。

但是您可以使用 $.fn.fadeOut(duration,complete)

duration: A string or number determining how long the animation will run.

complete: A function to call once the animation is complete.

代码

$('#ServicesContent').fadeOut(800, function (){
    $('#infoSlector').fadeIn();
    $('#motoDescContent').fadeIn();
    $('#goBackDiv').fadeIn("hidden");
});

关于jquery - 在 .delay() 中嵌入函数无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30161679/

相关文章:

jquery - 页面加载后如何加载图像?

jquery - $(this).attr 不起作用

html - 没有任何填充或空格的两列 Bootstrap 布局

javascript - 如何从动态创建的php文件中读取echo并刷新div中的echo

javascript - 没有效果的 CSS 属性,由 js getComputedStyle() 读取

html - 合并两个 html 文档并为第一个文档添加阴影效果

javascript - 每个 session 运行一次 javascript

javascript - 在 jquery 中创建和分配一个 css 类

javascript - 如果没有文本,如何使有序列表的数量消失

javascript - Jquery 不会将 &lt;textarea&gt; 值附加到特定的 div