如何在几秒钟后淡出 Alert::widget? [英] How to fade out an Alert::widget after some seconds?

查看:43
本文介绍了如何在几秒钟后淡出 Alert::widget?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了显示警报,我在视图中使用了此代码.

For showing the alert I am using this code in my view.

<?= Alert::widget() ?>

从控制器我使用这个代码设置闪光灯:

And From controller I am setting the flash by using this code:

Yii::$app->session->setFlash('success', 'Thank you for contacting us.');

现在我想在几秒钟后自动隐藏这个闪光灯,我该怎么做?

Now I want to hide this flash automatically after some seconds, How can I do this?

推荐答案

您可以使用 javascript 方法隐藏或 fadeOut() 布局顶部的警报如果您在布局中包含 yii\widgets\Alert 小部件以在您的网站上整体使用,则可以使用文件.

You can use the javascript method to hide or fadeOut() the alert on top of your layout file if you are including the yii\widgets\Alert widget in the layout for overall usage on your site.

$js=<<< JS
     $(".alert").animate({opacity: 1.0}, 3000).fadeOut("slow");
JS;

$this->registerJs($js, yii\web\View::POS_READY);

您可以相应地调整超时时间.

You can adjust the timeout accordingly.

这篇关于如何在几秒钟后淡出 Alert::widget?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆