JavaScript與css3字串波浪形抖動效果

antzone發表於2017-04-17

分享一段程式碼例項,它利用css3和js實現了字串波浪形抖動效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style type="text/css">
@keyframes move {
  0% {
   top: 0;
 }
 100% {
   top: 10px;
 }
}
#box {
  width: 200px;
 height: 100px;
 background: red;
 font-size: 20px;
 color: #fff;
}
#box span {
  position: relative;
}
</style>
<script>
window.onload = function() {
  var span = document.querySelectorAll('#box span');
 for (var index = 0; index < span.length; index++) {
   span[index].style.WebkitAnimation = span[index].style.animation = " .2s "
  + (index * 50)
  + "ms move linear infinite alternate";
 }
};
</script>
</head>
<body>
<div id="box">
 <span>L</span>
 <span>o</span>
 <span>a</span>
 <span>d</span>
 <span>i</span>
 <span>n</span>
 <span>g</span>
</div>
</body>
</html>

相關文章