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;
}
画像は画像配列を適切に循環しますが、トランジションが完了する時間よりも速くユーザーがトランジションすると、トランジションは有効になりません。
誰かがここで修正するためのアイデアを持っていますか?