如何使用动画自动更改图像?这是我在Javasript中的代码:
var ary=[
'images/image1.png',
'images/image2.jpg',
'images/image3.jpg',
'images/image4.jpg',
'images/image4.jpg',
'images/image4.jpg'
];
function Slide(id,ary,nu){
document.getElementById(id).src=ary[nu];
Slide[id]={nu:nu};
}
function nextImage(id,ary,ud){
var nu=(Slide[id]&&Slide[id].nu?Slide[id].nu:0)+ud;
Slide(id,ary,Math.min(Math.max(nu,0),ary.length-1));
}
感谢每一个答案。
答案 0 :(得分:0)
这里试试这个
var ary=[
'images/image1.png',
'images/image2.jpg',
'images/image3.jpg',
'images/image4.jpg',
'images/image4.jpg',
'images/image4.jpg'
];
var counter = 0;
setInterval(function() {slideshow();}, 4000);
maxCounter = ary.length;
function slideshow() {
img.style.backgroundImage = "url("+arr[i]+")";
if (counter == maxCounter) {
counter = 0;
} else {
counter++;
}
对于某些动画
#img{
-webkit-transition:background-image 1s linear;
-moz-transition:background-image 1s linear;
transition:background-image 1s linear;
}
HTML
<div id='img'></div>