javascript / html 片段:
<script>
var backgroundImages = new Array(); // create an array holding the links of each image
var backgroundImages = [
"style/images/bg0.png",
"style/images/bg1.png",
"style/images/bg2.png",
"style/images/bg3.png",
"style/images/bg4.png",
"style/images/bg5.png",
"style/images/bg6.png",
];
var ImageCnt = 0;
function nextImage(direction) // this should take into account the current value (starts at 3) and determines whether a higher or lower value should be returned based on the direction
{
ImageCnt = (ImageCnt + (direction == "left" ? backgroundImages.length-1 : 1)) % backgroundImages.length;
document.getElementById("body-1").style.background = "url('"+backgroundImages[ImageCnt]+"')";//put's the new background together for rendering by using the returned value from nextImage()
}
</script>
<div class="body-1" id="body-1"><!-- begin body 1 :: this will hold the topmost image slider -->
<div class="transition" id="trans-left" onclick='nextImage("left");return false;'><!-- begin transition left :: this will take advantage of rotation to use the same loaded image for both the left and right arrows -->
<img src="images/transition.png"/>
</div><!-- end transition left -->
<div class="transition" id="trans-right" onclick='nextImage("right");return false;'><!-- begin transition right :: this will take advantage of rotation to use the same loaded image for both the left and right arrows -->
<img src="images/transition.png"/>
</div><!-- end transition right -->
</div>
这里是涉及到的CSS,比较简单:
.body-1
{
margin-top: -50px;
padding: 0px;
width: 100%;
height: 470px;
background-color: #ebf6f7;
background-image: url('images/bg3.png');
background-size: 100% 470px;
transition: background-image 2s;
overflow: hidden;
}
图像在我的图像数组中正确循环,但如果用户转换的速度超过了转换完成的时间,则转换不会生效。
有人对这里的修复有想法吗?