简体   繁体   English

淡出结束后,将执行jQuery淡出回调函数

[英]JQuery fadeOut callback function is being executed after fadeOut is over

On a click of a button, i'm trying to fadeOut an image, and while it is fading out i'm changing the source of the image. 在单击按钮时,我试图淡出图像,而当图像淡出时,我正在更改图像的来源。 And then i'm using the fadeIn to show the new image. 然后我使用fadeIn来显示新图像。 This works fine in Chrome, and firefox. 在Chrome和Firefox中都可以正常工作。 However, in ie10, the image fades out, fades in, and then the new image appears. 但是,在ie10中,图像逐渐淡出,渐弱,然后出现新图像。 I can't find aa fix for it. 我找不到解决办法。 I've tried to prolong the duration of fadeOut, fadeIn. 我试图延长fadeOut,fadeIn的持续时间。 I've tried using setTimeout function. 我试过使用setTimeout函数。 i've tried using promise().done() function. 我试过使用promise()。done()函数。 I've tried using Jquery UI's hide/show w/ slide effect, and same issues are appearing. 我尝试使用Jquery UI的带幻灯片效果的隐藏/显示,并且出现了相同的问题。 Nothing seems to be working. 似乎没有任何作用。 I'd really appreciate any help. 我真的很感谢您的帮助。 Thanks 谢谢

me.$el.find('#printable-detail-static-imageRight').fadeOut('fast', function(){
                            me.$el.find('#printable-detail-static-imageRight').attr('src', me.options.samplePrints[k+i]);
                            me.disableNext();
                        });

                        me.$el.find('#printable-detail-static-imageRight').fadeIn('slow')

I'm pretty sure you need to put the .fadeIn method inside the callback function in order for it to be affected by the callback function. 我很确定您需要将.fadeIn方法放入回调函数中,以使其受到回调函数的影响。 In fact, I'd add another callback function to the .attr method to make sure that it fades back in only after the src has been changed. 实际上,我将向.attr方法添加另一个回调函数,以确保仅在src更改后才淡入。

Here's a jsFiddle I wrote to illustrate what I mean. 这是我写的jsFiddle来说明我的意思。

i am on a mac, but does this code works in ie ? 我在Mac上,但是此代码在ie中有效吗? jsFiddle 的jsfiddle

.html html的

<div id="content">Promises</div>
<button id="click">start animation</button>

.js .js文件

$("#click").on("click", function () {
    $('#content').fadeOut({
        duration: 1000,
        // run when the animation is complete
        complete: function () {
            $("#content").append($("<div>").addClass("fakeimg"));
        },
        // run when the animation is complete + 
        //it's promise is resolved
        done: function () {
            $('#content').fadeIn(1000);
        }
    });
});

this works: 这有效:

 me.$el.find('#printable-detail-static-imageRight').animate({
                        opacity:0
                    }, {
                        duration: 700,
                        step: function(now, fx){
                            if(fx.pos > 0.40 && fx.pos < 0.5){
                                $(this).attr('src', me.options.samplePrints[k+i]);
                                me.disableNext();
                            }
                            if (fx.pos ==1) {
                                $(this).animate({
                                    opacity:1
                                }, 200);
                            }
                        }
                    });

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

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