js和css3實現能夠展開和摺疊的摺扇效果

分享一段代碼實例,它實現了能夠展開和摺疊的摺扇效果。

具體效果大家可以使用鼠標懸浮或者離開進行測試。

代碼實例如下:

[HTML] 純文本查看 複製代碼運行代碼
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>展開和摺疊的摺扇效果</title>
<style>
html{
  overflow:hidden;
}
body{
  background:#00ffff;
}
div{
  width:10px;
  height:500px;
  background:#ff83fa;
  position:absolute;
  top:10%;
  left:50%;
  transform-origin:center 90%;
  transition: transform 2s;
  border-left:1px solid pink;
  border-right:1px solid pink;
}
div:before,
div:after{
  content:'';
  position:absolute;
  height:300px;
  width:20px;
}
div:before{
  border-top:        300px solid #dddddd;
  border-right:25px solid transparent;
}
div:after{
  left:-35px;
  border-top:300px solid white;
  border-left:25px solid transparent;
}
div:first-of-type:after,
div:last-of-type:before,
div:last-of-type:after{
  border-top:        300px solid #ff83fa;
}
body:hover div:nth-of-type(1){
  transform:rotate(-70deg)
}
body:hover div:nth-of-type(2){
  transform:rotate(-60deg)
}
body:hover div:nth-of-type(3){
  transform:rotate(-50deg)
}
body:hover div:nth-of-type(4){
  transform:rotate(-40deg)
}
body:hover div:nth-of-type(5){
  transform:rotate(-30deg)
}
body:hover div:nth-of-type(6){
  transform:rotate(-20deg)
}
body:hover div:nth-of-type(7){
  transform:rotate(-10deg)
}
body:hover div:nth-of-type(8){
  transform:rotate(0deg)
}
body:hover div:nth-of-type(9){
  transform:rotate(10deg)
}
body:hover div:nth-of-type(10){
  transform:rotate(20deg)
}
body:hover div:nth-of-type(11){
  transform:rotate(30deg)
}
body:hover div:nth-of-type(12){
  transform:rotate(40deg)
}
body:hover div:nth-of-type(13){
  transform:rotate(50deg)
}
body:hover div:nth-of-type(14){
  transform:rotate(60deg)
}
body:hover div:nth-of-type(15){
  transform:rotate(70deg)
}
</style>
<script>
window.onload = function () {
  document.addEventListener('mousemove', function (e) {
    this.body.style.transform = 'rotateZ(-' + e.y / 50 + 'deg)'
  }, false);
}
</script>
</head>
<body>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
</body>
</html>
發佈了7 篇原創文章 · 獲贊 11 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章