吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1298|回复: 0
收起左侧

[其他转载] 页面鼠标点击,模拟打气球效果

[复制链接]
rundreamer 发表于 2022-3-29 11:29
页面鼠标点击,模拟打气球效果
[HTML] 纯文本查看 复制代码
<!DOCTYPE html>
<html>
<head>
	<title>demo</title>
	<style type="text/css">
		*{
			margin: 0;padding: 0
		}
		body{
			overflow: hidden;
			background:#ccc;
		}
		.balloon{
			position: absolute;
			top: 0px;
			left: 0px;
			width: 160px;
			height: 160px;
			background: #faf9f;
			border-radius: 160px 160px 64px 160px;
			transform: rotate(45deg);
			box-shadow:  -8px -8px 80px -8px #873940 inset,18px 18px 24px pink;
			/*内阴影横向,纵向,羽化,影子大小,内阴影,两套阴影*/
		}
		/*伪元素,before和after*/
		.balloon::after{
			position: absolute;/*定位*/
			bottom: -5px;
			right: -2px;
			content: "";/*激活,内容为空必须有*/
			width: 0px;
			height: 0px;
			background:transparent;
			border: 8px solid transparent;
			border-right-color: rgba(240,98,122,0.5);
			transform: rotate(45deg);
			border-radius: 16px;
		}
	</style>
</head>
<body>
	<!-- <div class="balloon"></div> -->
	
</body>
	<script type="text/javascript">
		// 1利用js动态生成div 初始化节点;2气球动起来;3点击气球运动;4爆炸动画
		var num=10;//初始气球数量
		var bW=160;
		var wW=window.innerWidth;//宽度
		var wH=window.innerHeight;//高度
		var timer=null;//初始化定时器
		init(num);
		timer=setInterval(move,1000/30);//持续气球向上飞
		//初始化气球
		function init(num){
			for(var i=0;i<num;i++){
				var randomX=Math.random()*wW-bW;
				randomX=Math.max(0,randomX);
				var randomY=Math.random()*wH;
				var oBalloon=document.createElement('div');
				oBalloon.className='balloon';
				oBalloon.style.left=randomX+"px";
				oBalloon.style.top=wH-bW+"px";
				oBalloon.speed=Math.random()*5+1;
				document.body.appendChild(oBalloon);
			}
		}
		//
		function move(){
			var oBalloons=document.querySelectorAll('.balloon');
			for(var i=0,len=oBalloons.length;i<len;i++){
				oBalloons[i].style.top=
				oBalloons[i].offsetTop-
				oBalloons[i].speed+"px";
				oBalloons[i].onclick=function(){
					boom.call(this,function(){
						clearInterval(this.timer);
						this.parentNode.removeChild(this);
					}.bind(this));
					// 主动执行boom的时候改变this指向
				}		
			}
			// document.body.addEventListener('click',function(e){
			// 	if(e.target.className.toLowerCase()==='balloon'){
			// 		// 可以传递this,但是不好
			// 		boom.call(e.target,function(){
			// 			clearInterval(this.timer);
			// 			this.parentNode.removeChild(this);//移除自身
			// 		}.bind(this));
			// 		// e.target.parentNode.removeChild(e.target);
			// 		// init(1);
			// 	}		
			// },false)

		}
		// 闭包模块开发用上
		function boom(cb){
			this.timer=setInterval(function(){
				// 永远指向了window
				if(this.offsetWidth<10){	
					cb&&cb();init(1);
				}	
				this.speed++;
				this.style.width=this.offsetWidth-10+'px';
				this.style.height=this.offsetHeight-10+'px';
			}.bind(this),1000/60);
			// 
		}
	</script>
</html>
采用html+css实现效果,用于学习demo
QQ录屏20220329111803_20220329112055.gif

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
wapjltb + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-9-21 11:18

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表