滑鼠懸浮三形選單變叉號

antzone發表於2017-05-13

分享一段程式碼例項,它實現了滑鼠懸浮三形選單,變叉號的效果。

程式碼如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<title>螞蟻部落</title>
<style type="text/css">
.icon {
  width: 50px;
  height: 10px;
  padding: 10px 0;
  border-top: 10px solid #000;
  border-bottom: 10px solid #000;
  background: #000;
  background-clip: content-box;
}
.fa {
  cursor: pointer;
  width: 50px;
  height: 50px;
  transition: .3s ease;
}
.fa:hover>.icon {
  border: 0;
  background: none;
}
.icon:before,
.icon:after {
  position: absolute;
  content: "";
  width: 60px;
  height: 60px;
  transition: .3s ease;
  -webkit-transition: .3s ease;
  opacity: 0;
}
.icon:before {
  top: -5px;
  border-bottom: 10px solid #000;
}
.icon:after {
  top: 15px;
  border-top: 10px solid #000;
}
.fa:hover>.icon:before {
  opacity: 1;
  transform: rotate(135deg) translateX(5px) translateY(-25px);
  -webkit-transform: rotate(135deg) translateX(5px) translateY(-25px);
}
.fa:hover>.icon:after {
  opacity: 1;
  transform: rotate(-135deg) translateX(20px) translateY(39px);
  -webkit-transform: rotate(-135deg) translateX(20px) translateY(39px);
}
</style>
</head>

<body>
<div class="fa">
  <div class="icon"></div>
</div>
</body>
</html>

相關文章