fadeOut - > fadeIn无法正常工作

时间:2012-06-05 10:43:15

标签: javascript jquery

JS代码:

var forma = $('form#mali_oglas'),
    pomoc = $('div[role=pomoc]'),
    div = $('.mali_oglas_pomoc'),
    input = forma.find('input, textarea');   

    input.on('click', function(){
        var name = $(':input:focus').attr("name")
        pomoc.fadeOut('fast', function(){            
            div.find("[data-pomoc='" + name + "']").fadeIn('slow');            
            console.log(name);
        });
    });

HTML code:

<div class="mali_oglas_pomoc">
    <div data-pomoc="name" role="pomoc">
        1Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi pretium, urna nec varius sollicitudin, erat urna accumsan sapien, vel interdum enim risus id mi. Class aptent taciti sociosqu ad litora.
    </div>
    <div data-pomoc="body" role="pomoc">
        2Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi pretium, urna nec varius sollicitudin, erat urna accumsan sapien, vel interdum enim risus id mi. Class aptent taciti sociosqu ad litora.
    </div>.....    
</div>

有问题的div的CSS:

div[role="pomoc"] {position: absolute; top: 45px; right: 0;width: 250px; display: none}
div[role="pomoc"]:first-child {display: block}

它有效,但有点奇怪。首先,它将显示块应用于目标div,然后淡出并淡入。发生了什么?

链接: http://jsfiddle.net/AY2B3/

1 个答案:

答案 0 :(得分:1)

每个完成的动画都会触发一次fadeOut回调。在您的示例中,回调会多次执行,因为pomoc包含多个元素。奇怪的可能是与在同一元素上多次调用fadeIn相关的可视化工件。