简体   繁体   English

我如何在我的jQuery代码中加入淡入效果

[英]How can i put a fadein effect in my jquery code

I want to know how can i put the fadeIn code here? 我想知道如何在这里放置fadeIn代码? i have a gridview inside a gridview and i want to put a effect in it when the user clicks the "plus/minus" picture, as of now my effect is just a simple popup through the gridview, how can i put the fadeIn or slideDown effect into my code? 我在gridview中有一个gridview,并且我想在用户单击“加/减”图片时在其中添加效果,截至目前,我的效果只是通过gridview的简单弹出窗口,我该如何放置fadeIn或slideDown影响到我的代码?

below is my code 下面是我的代码

$("[src*=plus]").live("click", function() {
    $(this).closest("tr").after("<tr><td></td><td colspan ='100%'>" + $(this).next().html() + "</td></tr>");
    $(this).attr("src", "../Images/Icons/minus2.png");
});
$("[src*=minus]").live("click", function() {
    $(this).attr("src", "../Images/Icons/plus2.png");
    $(this).closest("tr").next().remove();
});

If you immediately add display:none to the element you spawn you should be able to fade it in. To fade out, you'll need to use a callback in the fadeOut function for removing the element, that way there's time for it to transition before you drop it. 如果立即在生成的元素上添加display:none,则应该可以将其淡入。要淡出,您需要在fadeOut函数中使用回调函数来删除该元素,这样就有时间过渡放下之前。 *Revised so the row fades and not the image, based on what you needed *根据您的需要进行了修改,以使行淡化而不是图像淡化

$("[src*=plus]").live("click", function () {
      $(this).closest("tr").after("<tr style='display:none;'><td></td><td colspan ='100%'>" + $(this).next().html() + "</td></tr>");
      $("tr[style*='display:none']").fadeIn(500);
      $(this).attr("src", "../Images/Icons/minus2.png");
});

$("[src*=minus]").live("click", function () {
      $(this).attr("src", "../Images/Icons/plus2.png");
      var removedTr = $(this).closest("tr").next();
      removedTr.fadeOut(500, function(){
         removedTr.remove();
      });
});

This will hide the content initially, allowing you to use fadeIn() 这将最初隐藏内容,使您可以使用fadeIn()

$("[src*=plus]").live("click", function () {
    var container = $(this).closest("tr"),
        newContent = $("<tr><td></td><td colspan ='100%'>" + $(this).next().html() + "</td></tr>").hide();
    container.after(newContent);
    newContent.fadeIn();
    $(this).attr("src", "../Images/Icons/minus2.png");
});

$("[src*=minus]").live("click", function () {
    $(this).attr("src", "../Images/Icons/plus2.png");
    $(this).closest("tr").next().fadeOut(function() {
        $(this).remove();
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM