<分区>
<分区>
我已经做了一些研究,但到目前为止我在互联网上找不到解决方案。
我建立了一个网站,我试图让背景图片在 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/