-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.html
81 lines (64 loc) · 2.15 KB
/
index.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="./demo.css">
</head>
<body>
<div class="nav-container" id="demo1">
<div class="nav-item one"></div>
<div class="nav-item two"></div>
<div class="nav-item three"></div>
<div class="nav-mask-three"></div>
<div class="nav-center"></div>
</div>
<div class="nav-container" style="margin-top:15px;" id="demo2">
<div class="nav-item one"></div>
<div class="nav-item two"></div>
<div class="nav-item three"></div>
<div class="nav-mask-three"></div>
<div class="nav-center"></div>
</div>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script>
var $container = $('#demo1');
$container.on('click', '.nav-item', function (e) {
var $this = $(this);
if ($this.hasClass('active')) return;
$this.addClass('active').siblings().removeClass('active');
var _this = this,
idx = $this.index();
$container.css('transform', 'rotate(' + idx * 120 + 'deg)');
}).on('click', '.nav-mask-three', function (e) {
$(this).prev().trigger('click');
});
// 始终像一个方向旋转
var $container2 = $('#demo2');
$container2.on('click', '.nav-item', function (e) {
var $this = $(this);
if ($this.hasClass('active')) return;
$this.addClass('active').siblings().removeClass('active');
var _this = this,
idx = $this.index();
var oldDeg = parseInt($container2[0].style.transform.substr(7), 10) || 0;
var aimDeg = idx * 120;
var newDeg = aimDeg;
var n = oldDeg / 360 >>> 0;
console.log(oldDeg, aimDeg);
if (oldDeg > newDeg) {
do {
newDeg = 360 * n + aimDeg;
n++;
} while (newDeg < oldDeg)
}
console.log(newDeg);
$container2.css('transform', 'rotate(' + newDeg + 'deg)');
}).on('click', '.nav-mask-three', function (e) {
$(this).prev().trigger('click');
});
</script>
</body>
</html>