CSS3图片旋转木马效果

CSS3图片旋转木马效果

模仿demo

资料

资料demo


img

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# html

<div class="stage_area">
<div class="container" id="container">
<img src="http://image.zhangxinxu.com/image/study/s/s128/mm1.jpg" alt="">
<img src="http://image.zhangxinxu.com/image/study/s/s128/mm1.jpg" alt="">
<img src="http://image.zhangxinxu.com/image/study/s/s128/mm1.jpg" alt="">
<img src="http://image.zhangxinxu.com/image/study/s/s128/mm1.jpg" alt="">
<img src="http://image.zhangxinxu.com/image/study/s/s128/mm1.jpg" alt="">
<img src="http://image.zhangxinxu.com/image/study/s/s128/mm1.jpg" alt="">
<img src="http://image.zhangxinxu.com/image/study/s/s128/mm1.jpg" alt="">
<img src="http://image.zhangxinxu.com/image/study/s/s128/mm1.jpg" alt="">
<img src="http://image.zhangxinxu.com/image/study/s/s128/mm1.jpg" alt="">
</div>
</div>

<div class="stage_button">
<button id="prev">上滑</button>
<button id="next">下滑</button>
</div>

# css

.stage_area {
width: 900px;
margin-left: auto;
margin-right: auto;
background: #f0f0f0;
-webkit-perspective: 800px;
-moz-perspective: 800px;
perspective: 800px;
position: relative;
padding: 100px 50px;
min-height: 100px;
}

.container {
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
transform-style: preserve-3d;

width: 128px;
height: 100px;
left: 50%;
margin-left: -64px;
position: absolute;

/* transform: rotateY(40deg); */

-webkit-transition: transform 1s;
-moz-transition: transform 1s;
transition: transform 1s;
}

.container img {
position: absolute;
}

.container img:nth-child(1) {
transform: rotateY(0deg) translateZ(195.839px);
}

.container img:nth-child(2) {
transform: rotateY(40deg) translateZ(195.839px);
}

.container img:nth-child(3) {
transform: rotateY(80deg) translateZ(195.839px);
}

.container img:nth-child(4) {
transform: rotateY(120deg) translateZ(195.839px);
}

.container img:nth-child(5) {
transform: rotateY(160deg) translateZ(195.839px);
}

.container img:nth-child(6) {
transform: rotateY(200deg) translateZ(195.839px);
}

.container img:nth-child(7) {
transform: rotateY(240deg) translateZ(195.839px);
}

.container img:nth-child(8) {
transform: rotateY(280deg) translateZ(195.839px);
}

.container img:nth-child(9) {
transform: rotateY(320deg) translateZ(195.839px);
}

# js

window.onload = init
function init(){
var prev = document.querySelector('#prev')
var next = document.querySelector('#next')
var container = document.querySelector('#container')
var len = 0

var transform = function(element, value, key) {
key = key || "Transform";
["Moz", "O", "Ms", "Webkit", ""].forEach(function(prefix) {
element.style[prefix + key] = value;
});

return element;
}

prev.addEventListener('click', function(){
var _this = this
len-=40

transform(container, 'rotateY('+ len +'deg)');

})

next.addEventListener('click', function(){
var _this = this
len+=40

transform(container, 'rotateY('+ len +'deg)');
})
}

js部分用了大佬demo的js方法(就是赞!!

打赏测试
显示 Gitment 评论