-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcss-3d.html
62 lines (60 loc) · 3.17 KB
/
css-3d.html
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
<!DOCTYPE html>
<html>
<head>
<title>css3-3d旋转木马效果</title>
<meta name="name" content="content" charset = "utf-8">
</head>
<link rel="stylesheet" type="text/css" href="css-3d.css">
<body>
<div class="d-rotate">
<h3>3d旋转效果--点击任意图片浏览</h3>
<div id="stage" class="d_stage_area">
<div id="container" class="container">
<!-- <img src="http://images2015.cnblogs.com/blog/561794/201604/561794-20160413010122691-69559955.jpg" width="128" height="96" id="img1"/>
<img src="http://images2015.cnblogs.com/blog/561794/201604/561794-20160413010158301-1687814878.jpg" width="128" height="96" id="img2"/>
<img src="http://images2015.cnblogs.com/blog/561794/201604/561794-20160413010311832-1730833656.jpg" width="128" height="96" id="img3"/>
<img src="http://images2015.cnblogs.com/blog/561794/201604/561794-20160413010330816-951755840.jpg" width="128" height="96" id="img4"/>
<img src="http://images2015.cnblogs.com/blog/561794/201604/561794-20160413010350285-1813069804.jpg" width="128" height="96" id="img5"/>
<img src="http://images2015.cnblogs.com/blog/561794/201604/561794-20160413010410801-943411344.jpg" width="128" height="96" id="img6"/>
<img src="http://images2015.cnblogs.com/blog/561794/201604/561794-20160413010430395-1452487381.jpg" width="128" height="96" id="img7"/>
<img src="http://images2015.cnblogs.com/blog/561794/201604/561794-20160413010447332-2127426646.jpg" width="128" height="96" id="img8"/>
<img src="http://images2015.cnblogs.com/blog/561794/201604/561794-20160413010506613-1828415192.jpg" width="128" height="96" id="img9"/> -->
</div>
</div>
</div>
</body>
<script>
(function(){
// css transform 变换
var transform = function(element, value, key) {
key = key || "Transform";
["Moz", "O", "Ms", "Webkit", ""].forEach(function(prefix) {
element.style[prefix + key] = value;
});
return element;
};
var $ = function(selector) {
return document.querySelector(selector);
};
// 获取元素
var eleStage = $("#stage"),
container = $("#container");
var indexPiece = 0,
htmlPic = '',
arrayPic = [1, 2, 3, 4, 5, 6, 7, 8, 9],
rotate = 360 / arrayPic.length;//40
arrayPic.forEach(function(i) {
htmlPic = htmlPic + '<img id="img'+ i +'" src="./'+ i +'.jpg" width = "128" height = "196"/>';
});
container.innerHTML = htmlPic;
var transZ = 64 / Math.tan((rotate / 2 / 180) * Math.PI);
// 添加事件监听器
container.addEventListener("click", function() {
transform(this, "rotateY("+ (-1 * rotate * ++indexPiece) +"deg)");
});
arrayPic.forEach(function(i, j) {
transform($("#img" + i), "rotateY("+ j * rotate +"deg) translateZ("+ (transZ) +"px)");
});
})();
</script>
</html>