demo:http://www.htmleaf.com/Demo/201501251274.html
1 .正6变形内角720度。
2 .:style="transform:divRotate(i)"这个是可以传值的。
3 ..vue里面的文件,只要是需要到的数据,必须在data里面声明。
4 .3D场景的dom层级结构一定要是这样 舞台--容器--显示内容
<template>
<div class="stage">
<div class="container" :style="{transform:containerRotate()}">
<div v-for="i in 9"
:style="{transform:divRotate(i)}"
class="img" >
{{i}}
</div>
</div>
<button @click="last">last</button>
<button @click="next">next</button>
</div>
</template>
<script>
export default {
data:function(){
return{
rotate:0,
worldZ:0,
worldY:0,
}
},
mounted(){
this.rotate=360/9;
this.worldZ= 50/Math.tan((this.rotate/2)/180 * Math.PI)+60
},
methods:{
divRotate(i){
return `translateX(10px) rotateY(${i*this.rotate}deg) translateZ(${this.worldZ}px)`
},
containerRotate(){
return `rotateX(-10deg) rotateY(${this.worldY}deg)`
},
last(){
this.worldY+=this.rotate;
},
next(){
this.worldY-=this.rotate;
}
}
}
</script>
<style>
.stage{
width: 900px;
height: 900px;
background: #eee;
perspective: 800px;
//关键
position: relative;
}
.container{
width: 128px;
height: 100px;
transition:all 1s;
transform-style: preserve-3d;
//关键
position: absolute;
left:50%;
top:30%;
}
.img{
width: 128px;
height: 100px;
box-shadow: 0 1px 3px rgba(0,0,0,.5);
transition:opacity 1s,transform 1s;
position:absolute;
/* *定位的时候他们一定要基于一个原点。* */
bottom: 0;
background: yellowgreen;
}
@keyframes zhuan {
0%{
transform: rotateY(0deg)
}100%{
transform:rotateY(360deg)
}
}
</style>