Scriptalicious - 出现在动态创建的元素上

时间:2013-11-25 23:43:04

标签: ajax prototypejs scriptaculous

我是Prototype的新手(我已经使用了jQuery多年)而且我试图淡化已经通过ajax请求插入DOM的元素。

我尝试了以下内容:

$('element').insert({
  bottom: '<div id="element2" style="display:none;">Test</div>'
});

new Effect.Appear( 'element2', { duration: 0.25 } );

元素已成功插入,但仍保持隐藏状态。

1 个答案:

答案 0 :(得分:0)

根据这个小提琴起作用http://jsfiddle.net/8KA6u/ - 但是你可能有竞争条件。尝试在下一次运行事件循环时运行Appear,将其包含在setTimeout()中,延迟为0

$('element').insert({
    bottom: '<div id="element2" style="display:none;">Test</div>'
});

setTimeout(function(){
    new Effect.Appear( 'element2', { duration: 0.25 } );
},0);

Scriptaculous还会直接向元素添加一些Effect方法,因此您可以像这样运行它们

setTimeout(function(){
    $('element2').appear({duration:0.25});
},0);

添加到元素的方法列表 http://madrobby.github.io/scriptaculous/effect-methods/

相关问题