0

我正在使用以下代码并尝试了许多其他代码以在幻灯片中显示图像。但一切都是徒劳的..我的代码中没有错误,但网页上没有显示单个图像..我的代码是:

<html>
<head>
<style>

body{

    background-color: black;
    padding:0;
    margin:0;
    width:320px;
    height:480px;

}
img{
    -webkit-transition-property:opacity;
    -webkit-transition-duration:3s;
    position:absolute;
    width:320px;
    height:auto;

}
img.fade-out{opacity:0;}
img.fade-in{opacity:1;}

</style>
</head>
<body>

<img src = "Slide1.JPEG";/>
<img src = "Slide2.JPEG";/>
<img src = "Slide3.JPEG";/>
<img src = "Slide4.JPEG";/>


var interval = 4 * 20;

var images = document.getElementsByTagName("img");
var imageArray = [];
var imageCount = images.length;
var current =0;

var randomize = funtion() {

    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

1 回答 1

1

第一个错误:

Yor aur using file type in caps (.JPEG) it should be .jpeg / .jpg

第二个错误:

You forget to type the <script> tag at the starting of JavaScript code.

第三个错误:

You are using invalid function keyword (funtion) 

var randomize = "funtion"() {
    return ( Math.round(Math.random() * 3 - 1.5 ));
}

现在输入这段代码,它应该可以工作......

    <html>
<head>

<style>

身体{

background-color: black;
padding:0;
margin:0;
width:320px;
height:480px;

}

img{
-webkit-transition-property:opacity;
-webkit-transition-duration:3s;
position:absolute;
width:320px;
height:auto;

}

img.fade-out{opacity:0;}
img.fade-in{opacity:1;}


</style>
</head>
<body>


<img src = "Slide1.jpg" />
<img src = "Slide2.jpg" />
<img src = "Slide3.jpg" />
<img src = "Slide4.jpg" />


<script>
var interval = 4 * 20;

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>
于 2012-08-30T08:05:19.457 回答