开发者

fadeTo executes before .attr change though first in source

开发者 https://www.devze.com 2023-01-06 17:56 出处:网络
Here is a piece of code: $(document).ready(function() { $(\'#nextBtn\').live(\'click\', function() { $(this).attr(\'id\',开发者_运维问答 \'next2Btn\')

Here is a piece of code:

$(document).ready(function() {
    $('#nextBtn').live('click',
    function() {
        $(this).attr('id',开发者_运维问答 'next2Btn')
        $('#cs_contentToSlide').animate({
            left: '-=500',
        },
        200,
        function() {
            $('#stateGraphic').attr('src', 'images/state2_3stage.gif');
             $('#mainGraphic').fadeTo(900, 0.10);
    $('#mainGraphic').attr('src', 'images/assess3.gif');
    $('#mainGraphic').fadeTo(300, 1.0);            });

    });
});

I don't understand why the .attr edit on #mainGraphic occurs before the fade that precedes it in the source order.

What should happen is: a click is made, something slides, the #mainGraphic fades down to almost nothing, gets replaced, then fades back up.

As it is, I click, the slide is made, then #mainGraphic gets replaced and then fades in/out.

It appears that .attr changes are more senior to fades?


.attr() changes are not part of the FX queue, so they happen asynchronously from effects.

One option is to call the .attr() change in the .fadeTo() callback.

...
$'#mainGraphic'.fadeTo(900, 0.10, function(){
    $(this).attr('src', 'images/assess3.gif');
})
.fadeTo(300, 1.0);
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号