<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>利用JS实现文字的聚合动画效果</title>
<style>
.boxWrap1{width: 160px;height: 417px;position: relative;margin:0px auto;}
.boxWrap1 img{width: 100%;}
.boxWrap1 div{background: url(http://itakeo.com/wpimg/2_1.png) no-repeat;background-size: 160px auto; position: absolute; left: 0px;top: 0px;
}
.boxWrap1.set div{ opacity: 1!important;
transform:perspective(800px) translate3d(0px,0px,0px) rotate(0deg) scale(1)!important;
-moz-transform:perspective(800px) translate3d(0px,0px,0px) rotate(0deg) scale(1)!important;
-webkit-transform:perspective(800px) translate3d(0px,0px,0px) rotate(0deg) scale(1)!important;
}
.boxSiteWrap{ width: 100%;overflow: hidden;height: auto; background: #000;padding: 140px 0}
.boxSiteWrap button{cursor:pointer;display: block;font-size: 16px; width: 140px;height: 40px; background: #fff;color: #000;border:none;margin:30px auto;}
</style>
</head> <body>
<div class="boxSiteWrap">
<div class="boxWrap1"></div>
<button>重新加载</button>
</div> <script>
window.addEventListener('load',function(){
;(function(){
function init(){
var box = document.querySelector('.boxWrap1')
var c=4,r=8;
var w = box.offsetWidth/c,h = box.offsetHeight/r;
for(var i=0;i<r;i++){
for(var j=0;j<c;j++) {
var _div=document.createElement('div');
var _left = j * w,_top = i * h;
_div.style.cssText = 'width:'+w+'px;height:'+h+'px;left:'+_left+'px;top:'+_top+'px; opacity:0;background-position:'+(-_left) + 'px ' + (-_top) + 'px';
_div.style.transition = _div.style.MozTransition = _div.style.WebkitTransition = 'all '+ Random(1,1.8) +'s ease';
_div.style.transform = _div.style.MozTransform = _div.style.WebkitTransform = 'perspective(800px) translate3d('+Random(-200,200)+'px, '+Random(-200,200)+'px,300px) rotate('+Random(-90,90)+'deg) scale('+ Random(0,2) +')'
box.appendChild(_div);
};
};
setTimeout(function(){
box.classList.add('set')
},100);
function Random(start,end){
return Math.random()*(end-start)+start;
};
};
init();
var flag = true;
document.querySelector('button').onclick = function(){
if(flag){
document.querySelector('.boxWrap1').classList.remove('set')
setTimeout(function(){
document.querySelector('.boxWrap1').innerHTML = '';
init();
flag = true;
},1200);
flag = false;
};
};
})();
});
</script>
</body>
</html>

demo:https://controllerone.github.io/demo/piece.html

原文链接:http://itakeo.com/blog/2015/12/14/imgcover/?none=123

最新文章

  1. webpack-dev-server、webpack-dev-middleware、webpack-hot-middleware区别
  2. 【GOF23设计模式】中介者模式
  3. ios外包公司—北京动点软件分享:IOS工程自动打包并发布脚本实现
  4. 001MSP430概述
  5. [java bug记录] java.util.zip.ZipException: invalid code lengths set
  6. Hibernate三 关联关系
  7. d3d纹理参数
  8. Struts2(四)Struts2配置文件的配置
  9. ubuntu16.04开机花屏蓝屏解决方案
  10. git Remote: HTTP Basic: Access denied Git failed with a fatal error.
  11. 洛谷P4592 [TJOI2018]异或(可持久化01Trie)
  12. 信息摘要算法之六:HKDF算法分析与实现
  13. dygod.net
  14. go中 -strconv包的使用
  15. WINFROM窗体实现圆角
  16. 《转》 java.lang.OutOfMemoryError - 关于java的内存溢出
  17. 使用NetHogs监控进程网络使用情况
  18. spark on alluxio和MR on alluxio测试(改进版)【转】
  19. [COGS 0407][NOIP 2009] 靶形数独
  20. HBase 文件读写过程描述

热门文章

  1. angular 页签
  2. 2 _ 基本框架 _ 检测VMX环境
  3. .NET中DataTable的常用操作
  4. gstore安装
  5. mysql emoji存储问题
  6. 第一个简单netty程序
  7. 11.Hibernate一对多关系
  8. 如何正确使用 Flink Connector?
  9. webpack4.0打包的时候一些技巧
  10. php四种文件加载语句