JavaScript和css3點贊放大效果

admin發表於2017-04-17

分享一段程式碼例項,它實現了點贊放大效果,效果是JavaScript和css3結合實現。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style type="text/css">
* {
  margin: 0;
  padding: 0;
}
.box {
  width: 100px;
  height: 100px;
  margin: 100px auto;
  position: relative;
  border: 1px solid #ccc;
}
.reward, .big {
  font-size: 38px;
  color: green;
  display: block;
  position: absolute;
  top: 20px;
  left: 30px;
  transition: all .25s ease-in-out;
}
.box .big {
  position: fixed;
  top: 50%;
  left: 50%;
  margin: -100px 0 0 -100px;
  font-size: 200px;
  animation: gogo 1.5s 1;
  display: none;
  opacity: 0;
}
@keyframes gogo {
  0% {
    transform: scale(1);
    opacity: 0.5;
  }
  30% {
    -webkit-transform: scale(1);
    -moz-transform: scale(1);
    -ms-transform: scale(1);
    -o-transform: scale(1);
    transform: scale(1);
    opacity: 1;
  }
  70% {
    transform: scale(3);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 0;
  }
}
</style>
<script type="text/javascript">
window.onload = function () {
  var icon = document.getElementById('icon');
  var bigger = document.getElementById('bigger');
  icon.onclick = function () {
    bigger.style.display = 'block';
  }
}
</script>
</head>
<body>
  <div class="box">
    <i class="iconfont reward" id="icon">贊</i>
    <i class="iconfont big" id="bigger">贊</i>
  </div>
</body>
</html>

相關文章