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 代码:
<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/