css動態邊框效果

antzone發表於2017-03-14

分享一段程式碼例項,它實現了動態邊框效果,滑鼠懸浮即可演示效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
* {
  margin: 0;
  padding: 0;
}
.box {
  width: 1190px;
  margin: 0 auto;
  padding-top: 50px;
  height: 300px;
}
.border_animation {
  border: 1px solid #eee;
  width: 220px;
  height: 260px;
  float: left;
  margin-right: 10px;
  position: relative;
}
.border_animation .border_top {
  position: absolute;
  height: 1px;
  width: 0;
  font-size: 0;
  background: #666666;
  top: 0;
  left: 0;
  transition: all 0.5s ease-out;
}
.border_animation .border_right {
  position: absolute;
  height: 0px;
  width: 1px;
  font-size: 0;
  background: #666666;
  bottom: 0;
  right: 0;
  transition: all 0.5s ease-out;
}
.border_animation .border_bottom {
  position: absolute;
  height: 1px;
  width: 0px;
  font-size: 0;
  background: #666666;
  right: 0;
  bottom: 0;
  transition: all 0.5s ease-out;
}
.border_animation .border_left {
  position: absolute;
  height: 0px;
  width: 1px;
  font-size: 0;
  background: #666666;
  left: 0;
  top: 0;
  transition: all 0.5s ease-out;
}
.box .hover .border_top, .box .hover .border_bottom {
  width: 220px;
}
.box .hover .border_left, .box .hover .border_right {
  height: 260px;
}
</style>
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script>
$(function () {
  $(".border_animation").mouseenter(function(){
    $(this).addClass("hover");
  });
  $(".border_animation").mouseleave(function(){
    $(this).removeClass("hover");
  });
});
</script>
</head>
<body>
  <div class="box">
    <div class="border_animation">
      <div class="border_top"></div>
      <div class="border_right"></div>
      <div class="border_bottom"></div>
      <div class="border_left"></div>
      <div></div>
    </div>
    <div class="border_animation">
      <div class="border_top"></div>
      <div class="border_right"></div>
      <div class="border_bottom"></div>
      <div class="border_left"></div>
      <div></div>
    </div>
    <div class="border_animation">
      <div class="border_top"></div>
      <div class="border_right"></div>
      <div class="border_bottom"></div>
      <div class="border_left"></div>
      <div></div>
    </div>
    <div class="border_animation">
      <div class="border_top"></div>
      <div class="border_right"></div>
      <div class="border_bottom"></div>
      <div class="border_left"></div>
      <div></div>
    </div>
    <div class="border_animation">
      <div class="border_top"></div>
      <div class="border_right"></div>
      <div class="border_bottom"></div>
      <div class="border_left"></div>
      <div></div>
    </div>
  </div>
</body>
</html>

相關文章