如何在CakePHP中使用jQuery的fadeIn效果?

时间:2012-10-05 16:49:33

标签: php jquery cakephp cakephp-2.0

我是JavaScript的新手,我发现它在CakePHP中特别令人困惑。

我有一个AJAX调用,它获取另一个页面并将其放在div中。这有效,但我希望它能够淡出而不仅仅是出现。

这是我到目前为止的代码:

$this->Js->get('#load_items');
$this->Js->event('click', $this->Js->request(
    array('action' => 'plain_items'),
    array(
        'async' => true, 
        'update' => '#items',
        'complete' => 'onComplete'
    )
));
$this->Js->event('onComplete', $this->Js->effect('fadeIn'));

echo '<div id="items"></div>';
echo $this->Form->submit('Load Items', array('id' => 'load_items'));

获取“plain_items”视图并将其加载到“items”div中没有​​问题,但我无法在加载时将其淡化。我做错了什么?

1 个答案:

答案 0 :(得分:0)

$ this-&gt; Js这包含#load_items的对象,如果你想淡入div #items,那么你需要取这个div的对象然后淡入...见下面的例子

$this->Js->event('click', $this->Js->request(
    array('action' => 'plain_items'),
    array(
        'async' => true, 
        'update' => '#items',
        'before' => $this->Js->get('#items')->effect('fadeOut', array('buffer' => false)),
        'complete' => $this->Js->get('#items')->effect('fadeIn', array('buffer' => false))
    )
));