jquery - 延迟 5 秒后用文本替换图像

标签 jquery image html text replace

目标
使用 jQuery 在延迟 5 秒后将一个 div 替换为另一个。

描述
我想在一个 div 中显示一个图像 5 秒,然后它应该被另一个 div 中的文本替换。

HTML 代码

<div id="outer">Image here</div>
<div id="text">Text here</div>

jQuery 代码

<script type="text/javascript">
    $(document).ready(function()
    {
        setTimeout(function()
        {
            $("div#outer").fadeOut("slow", function ()
            {
                $("div#outer").remove();
            });
         }, 5000);
     });
</script>

提前致谢。

最佳答案

试试这个:

<script type="text/javascript">
        $(document).ready(function()
        {
            setTimeout(function()
            {
                $("div#outer").fadeOut("slow", function ()
                {
                    $("div#outer").hide();
                    $("div#text").show();
                });
             }, 5000);
         });
    </script>

或者,如果您实际上想将 div text 中包含的文本移动到 div outer 中,请执行以下操作:

<script type="text/javascript">
            $(document).ready(function()
            {
                setTimeout(function()
                {
                    $("div#outer").fadeOut("slow", function ()
                    {
                        $("div#outer").html($("div#text").html()); //.html or .text
                    });
                 }, 5000);
             });
        </script>

关于jquery - 延迟 5 秒后用文本替换图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10546946/

相关文章:

javascript - html中的表单提交触发器

javascript - 动态 float 气泡..使用Jquery

java - 二值图像数据的高效存储

html - 如何使用 Bootstrap 用一张图像覆盖整个屏幕背景

jquery - 仅在网站第一次加载 localStorage 时显示 DIV

javascript - 在 Chrome/Firefox 中全屏按下 escape 时不会触发 Keydown 事件

javascript - 控制台.log();如何调试javascript

javascript - 如何在react中加载图像并转换为blob

android - 我到这里来将图像添加到我的 android 应用程序,但有一条错误行

html - 如何使用高度:50% if the container height is not defined?