【CSS】ボーダーが2方向に動いて四角形をつくるラインアニメーションの実装方法のデモページ/CSS Animation where two lines are square(Demo page)

※デベロッパーツール等でソースコードをご確認ください

スポンサーリンク

CSS

.block {
  width: 300px;
  margin: 70px auto 0;
}
.a {
  position: relative;
  width: 100%;
  height: 300px;
}
.a span {
  position: absolute;
}

.a span:nth-child(1),.a span:nth-child(4) {
  top: 0;
  background-color: #7f7f7f;
  transition: all .9s linear;
}

.a span:nth-child(3),.a span:nth-child(2) {
  left: 0;
  background-color: #7f7f7f;
  transition: all .9s linear;
}

.a span:nth-child(1) {
  left: 0;
  width: 0;
  height: 1px;
  transform-origin: left center;
}

.a span:nth-child(2) {
  top: 0;
  width: 1px;
  height: 100%;
  transform-origin: center top;
  transform: scaleY(0);
}

.a span:nth-child(3) {
  bottom: 0;
  width: 0;
  height: 1px;
  transform-origin: left center;
  transition-delay: .9s;
}

.a span:nth-child(4) {
  right: 0;
  width: 1px;
  height: 100%;
  transform: scaleY(0);
  transform-origin: center top;
  transition-delay: .9s;
}

.block.active .a span:nth-child(3),
.block.active .a span:nth-child(1) {
  width: 100%;
}
.block.active .a span:nth-child(4),
.block.active .a span:nth-child(2) {
  transform: scaleY(1);
}

@media screen and (max-width:640px){
  .block {
    width: 85%;
  }
}
  

JavaScript

$(window).on('load', function(){
    $(".block").addClass("active");
  });