0

我正在尝试创建一个带有淡入淡出的图像滑块。我在网上找到的每组代码都只能在 Mac/Safari 中使用,而不是在 Mac/Chrome 或 Mac/Firefox 中。我在 Windows 上尝试过,它适用于 Windows/Chrome 和 Windows/Firefox,但不适用于 Windows/IE。有什么我做错了吗?我还想在我的图像中添加一些弹出式 peekaboos(标题)。这是我的代码:

<!doctype html>
<html>
<head>
<style>
body{
background-color:black;
padding:0;
margin:0;
width:850px;
height:300px;

}
img{
-moz-transition-property: opacity;
-moz-transition-duration: 3s;
-webkit-transition-property:opacity;
-webkit-transition-duration: 3s;
position:absolute;
width: 850px;
height:300px
}
img.fade-out{opacity:0}
img.fade-in{opacity:1}
</style>
</head>
<body>
<img src="Image1.jpg"/>
<img src="Image2.jpg"/>
<img src="Image3.jpg"/>
<img src="Image4.jpg"/>
<script>
var interval = 4 * 20; // Seconds between change
var images = document.getElementsByTagName("img");
var imageArray = [];
var imageCount = images.length;
var current = 0;

var randomize = function(){
return (Math.round(Math.random() * 3 - 1.5));
}
for(var i = 0; i < imageCount; i++){
images[i].className = 'fade-out';
imageArray[i] = images[i];
}
imageArray.sort(randomize);

var fade = function(){

imageArray[current++].className = 'fade-out';
if(current == imageCount){
current = 0;
imageArray.sort(randomize);
}
imageArray[current].className = 'fade-in';

setTimeout(fade, interval * 100);
};
fade();
</script>
</body>
</html>
4

0 回答 0