图片碎片化 可支持操作和定时

6 篇文章 0 订阅

图片碎片化 可支持操作和定时

burst() {
				var that = this;
				var ready = true;
				var img = document.querySelector('#container');
				var S = 1;
				var R = 4;
				var C = 7;
				var W = parseInt(window.getComputedStyle(img)['width']);
				var H = parseInt(window.getComputedStyle(img)['height']);
				var N = 2;
				var maxW = N * W;
				var maxH = N * H;
				var now = 0;
				var info = ['https://kkkk1000.com/images/ExplosionPictureSwitching/1.jpg',
					'https://kkkk1000.com/images/ExplosionPictureSwitching/2.jpg',
					'https://kkkk1000.com/images/ExplosionPictureSwitching/3.jpg',
				];
				img.style.background = 'url(' + that.info[0] + ') no-repeat';
				var next = function() {
					return (now + 1) % that.info.length;
				}
				// img.onmouseover = function() {
				// }
				setInterval(function(){
					that.shuipian(ready,now,img,R,C,W,H,maxW,maxH,S,next);
				},2000)
			},
			shuipian(ready,now,img,R,C,W,H,maxW,maxH,S,next){
				var that = this;
				// if (!ready) return;
				ready = false;
				var html = document.createDocumentFragment();
				if (that.now+1 == that.info.length) {
					img.style.background = 'url(' + that.info[0] + ') no-repeat';
				} else {
					img.style.background = 'url(' + that.info[1] + ') no-repeat';
				}
				var posArr = [];
				var k = 0;
				for (var i = 0; i < R; i++) {
					for (var j = 0; j < C; j++) {
						posArr[k] = {
							left: W * j / C,
							top: H * i / R,
							endLeft: maxW * j / C - (maxW - (maxW - W) / C - W) / 2,
							endTop: maxH * i / R - (maxH - (maxH - H) / R - H) / 2,
						};
						var debris = document.createElement("div");
						var url = that.info[that.now];
						debris.style.cssText =
							` position: absolute; width: ${Math.ceil(W / C)}px; height: ${Math.ceil(H / R)}px; background: url(${url}) -${posArr[k].left}px -${posArr[k].top}px no-repeat; left: ${posArr[k].left}px; top: ${posArr[k].top}px; opacity:1; transition:${that.randomNum(0.1, S)}s ease; `;
						html.appendChild(debris);
						k++;
					}
				}
				img.appendChild(html);
				var debrisAll = img.children;
				setTimeout(function() {
					for (var i = 0; i < debrisAll.length; i++) {
						var l = posArr[i].endLeft;
						var t = posArr[i].endTop;
						debrisAll[i].style.cssText +=
							` left : ${l}px; top : ${t}px; opacity :0; transform:perspective(500px) rotateX(${that.randomNum(-180, 180)}deg) rotateY(${that.randomNum(-180, 180)}deg) rotateZ(${that.randomNum(-180, 180)}deg) scale(${that.randomNum(1.5, 3)}); `;
					}
					setTimeout(function() {
						img.innerHTML = '';
						ready = true;
						// that.now = next();
						if(that.now+1 >= that.info.length){
							that.now = 0;
						}else{
							that.now = that.now + 1;
						}
					}, S * 1000);
				}, 100);
			},
				randomNum(n, m) {
					return Math.random() * (m - n) + n;
				},
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值