滑鼠懸浮底部具有動態延伸條效果程式碼例項

antzone發表於2017-03-06

分享一段程式碼例項,它實現了滑鼠懸浮,底部出現動態延展條的效果。

滑鼠離開後,延展條會小時,程式碼例項如下:

[HTML] 純文字檢視 複製程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
#myid{
  width:120px;
  height:50px;
  background:hsl(0,0%,90%);
}
#myid li{
  position: relative;
  display: block;
}
#myid li a{
  position: relative;
  display: block;
  text-decoration:none;
  padding: 10px 15px;
  color: #9d9d9d;
  webkit-transition: all .2s ease-out;
  -moz-transition: all .2s ease-out;
  -o-transition: all .2s ease-out;
  -ms-transition: all .2s ease-out;
  transition: all .2s ease-out;
}
#myid li a i{
  display: block;overflow: hidden;
  position: absolute;
  top: 14px;
  width: 25px;
  height: 15px;
}
/* i的style位置*/
#myid li a:hover i {background-position: 0 -20px;}
#myid li a span {margin-left: 10px;}
#myid li a::after {
  display: block;
  bottom: 5px;
  left: 60%;/* 控制左邊的初始長度*/
  right: 70%;/* 控制右邊的初始長度*/
  margin: 0 -30px;/* 控制延伸線條的初始位置*/
  min-width:20%;
  height: 2px;
  background:black;
  content: '';
  z-index: 0;
  -webkit-transition: all 1.2s ease-out;
  -moz-transition: all 1.2s ease-out;
  -o-transition: all 1.2s ease-out;
  -ms-transition: all 1.2s  ease-out;
  transition: all 1.2s ease-out;
  position: absolute;
}
#myid> li > a:hover{color: #6bc30d!important;}
#myid > li > a:hover:after{
  left: 17px;/* 控制左邊的延伸後的結束位置*/
  right: 26px;/* 控制右邊的延伸後的結束位置*/
  margin: 0;
  background: red;
  opacity: 0.5;
}
</style>
</head>
<body>
<div id="myid">
  <li class="logo">
    <a href="#">
      <i class="dhnone font20"></i>
          <span>螞蟻部落</span>
    </a>
  </li>
</div>
</body>
</html>

相關文章