javascript - 定时图像变化

标签 javascript jquery css jquery-plugins

<分区>

我已经做了一些研究,但到目前为止我在互联网上找不到解决方案。

我建立了一个网站,我试图让背景图片在 3 秒后更改,更改后它停留在第二张图片上,没有无限循环。

我知道这可以用 CSS3 来完成,但是网站需要广泛兼容,所以我猜 JQuery/JS 是最好的解决方案?如果是这样,我该如何实现?

编辑

这是我使用的代码

<script>
        setTimeout(function(){
            document.getElementById(header).style.background = "url(<?php bloginfo('template_url') ?>/img/girl-color.jpg)";
        }, 3000);
    </script>
  </head>
  <body>
    <header id="header" style="background: url(<?php bloginfo('template_url') ?>/img/girl-bw.jpg);">

但是我有这个错误。 “未捕获的类型错误:无法读取 null 的属性‘style’”

最佳答案

Vanilla JS,假设背景与主体相关:

setTimeout(function(){
     document.body.style.background = "url(here_goes_the_url)";
}, 3000);

关于javascript - 定时图像变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24572007/

上一篇:html - 如何在 html 文档中链接 html 文件?

下一篇:html - 如何在 Chrome 中设置背景图片?

相关文章:

javascript - CSS <td> 标签影响整个页面

html - 如何控制select标签的宽度?

php - 在图像之间添加空间

javascript - Firepad 获取并保存内容

javascript - 在 HTML 网页中运行 python 方法

jQuery 命名空间全局变量

javascript - 在 Codeigniter 端访问 Ajax POST 变量时出现问题

java - 在 JavaFX 中实现只读样式?

javascript Array.prototype.push 如何连接

javascript - IPython:将 Javascript 脚本添加到 IPython notebook