四张图片要实现无缝轮播,我的第一个想法就是立方体,然后每次去转动 然后就自己尝试了一下
CSS部分:
<style>
*{
margin: 0;
padding: 0;
list-style: none;
}
#focus{
/*overflow: hidden;*/
position: relative;
width: 1100px;
height: 458px;
margin: 100px auto;
}
#focus #dot{
position: absolute;
float: left;
left: 0;
bottom: 0;
height: 35px;
width: 1100px;
}
#focus #dot div{
position: absolute;
width: 272px;
height: 35px;
line-height: 35px;
text-align: center;
background-color: rgba(0,0,0,0.6);
color: white;
float: left;
margin-left: 1px;
cursor: pointer;
bottom: 0;
}
#focus #dot div:nth-child(1){
left: 0;
}
#focus #dot div:nth-child(2){
left: 276px;
}
#focus #dot div:nth-child(3){
right: 276px;
}
#focus #dot div:nth-child(4){
right: 0;
}
#focus #aImg{
position: absolute;
left: 0;
top: 0;
width: 1100px;
height: 458px;
transition: all ease 0.8s;
transform-style: preserve-3d;
transform: rotateY(0deg);
}
#focus #aImg li{
position: absolute;
width: 1100px;
height: 458px;
}
#focus #aImg li:nth-child(1){
transform: translateZ(550px);
}
#focus #aImg li:nth-child(2){
transform: rotateY(90deg) translateZ(550px);
}
#focus #aImg li:nth-child(3){
transform: rotateY(180deg) translateZ(550px);
}
#focus #aImg li:nth-child(4){
transform: rotateY(-90deg) translateZ(550px);
}
#focus #aImg li img{
width: 100%;
}
</style>
html部分:
<div id="focus">
<ul id="aImg">
//图片宽度是 1100px 说出宽度是因为要实现立体拼接 要根据图片的宽度去调整Z轴的距离
<li><img src="img/shouye1.jpg" alt=""></li>
<li><img src="img/shouye5.jpg" alt=""></li>
<li><img src="img/shouye3.jpg" alt=""></li>
<li><img src="img/shouye4.jpg" alt=""></li>
</ul>
</div>
JS代码:
<script>
var aImg = document.getElementById("aImg");
var dist = 0;
function show() {
aImg.style.transform ="rotateY("+dist*(-90)+ "deg)";
}
setInterval(function () {
dist++;
show()
},2000)
</script>