【特效】js打造黑客帝国文字特效

不多说,直接贴代码
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>document</title>
	<style type="text/css">
		body{
			background: #111;
		}
		#cont{
			background: #000;
			width: 600px;
			height: 800px;
			margin: 20px auto;
			position: relative;
		}
		.divbox{ 
			position: absolute;
			top:0px;
			width: 6px;
		}
		.snows{  
			display: block;
		}

	</style>
	
</head>
<body> 
	<div id="cont"> 
	</div>
	<button id="btn">停止</button>
	<button id="start">开始</button>
	<script type="text/javascript">
		// 获取元素
		var $snows = document.getElementsByTagName('span');
		var $cont = document.getElementById('cont') 
		var $btn = document.getElementById('btn') 
		var $start = document.getElementById('start') 
		var _top,
			_left, 
		 	cont=66,
		 	timer,
		 	r,
		 	g,
		 	b,
		 	speed=60;
		 	 
		
		//创建span 
		var $creatSnows = null;
		var $creatDivs = null; 
		 
		document.body.οnlοad=function(){
			
			
			move();
			// alert($creatDivs) 
			$btn.οnclick=function() {
				/* Act on the event */
				clearInterval(timer)
				// alert()
			};
			$start.οnclick=function() {
				/* Act on the event */
				clearInterval(timer)
				timer = setInterval(function(){
					var divBoxList =document.getElementsByName('singlebox'); 
					// alert(divBoxList.length);
					var color = borthColor(); 
				 	for (var j = 0; j < divBoxList.length; j++) {  
						
					 	if (divBoxList[j].offsetTop >= 500){
					 		// clearInterval(timer);  
					 		divBoxList[j].style.top=Math.floor(Math.random()*500)+'px';
					 		divBoxList[j].style.left=Math.floor(Math.random()*600)+'px'; 
					 	}else{ 
					 	 	divBoxList[j].style.color='#'+color.r+color.g+color.b; 
					 		divBoxList[j].style.top = divBoxList[j].offsetTop+speed+'px';  
					 		console.log(divBoxList.length); 

					 	}; 


				 	};
					 
				},100);
				// alert()
			};
		};
		 
		

		// // 移动函数
		function move(){

			
			appendDivList();
				// alert('hello')
			timer = setInterval(function(){
				var divBoxList =document.getElementsByName('singlebox'); 
				// alert(divBoxList.length);
				var color = borthColor(); 
			 	for (var j = 0; j < divBoxList.length; j++) {  
					
				 	if (divBoxList[j].offsetTop >= 500){
				 		// clearInterval(timer);  
				 		divBoxList[j].style.top=Math.floor(Math.random()*500)+'px';
				 		divBoxList[j].style.left=Math.floor(Math.random()*600)+'px'; 
				 	}else{ 
				 		if (j>15) {
			 				divBoxList[j].style.color='#'+color[15]; 
				 		}else{
					 	 	divBoxList[j].style.color='#'+color[j]; 

				 		};
				 		divBoxList[j].style.top = divBoxList[j].offsetTop+speed+'px';  
				 		console.log(divBoxList.length); 

				 	}; 


			 	};
				 
			},100);

		} 

		// 把生成的div盒子列表添加到大盒子中
		function appendDivList(){
				var divBoxList = drawDivsList();
				
				for (i = 0; i < divBoxList.length; i++) {
					$cont.appendChild(divBoxList[i]); 
					divBoxList[i].style.top=Math.floor(Math.random()*500)+'px';
			 		divBoxList[i].style.left=Math.floor(Math.random()*600)+'px';  
				}
				return $cont;
				
		}

		// color 随机生成函数
 		function borthColor(){
 			var color = new Array();
 			for (var i = 0; i < 17; i++) {
 				var g = i.toString(16);
 				color.push('0'+g+'0');
 			}; 
			console.log('color snows:'+color.length) 
			return color;
 		}
 		
 		// create 1 or 0
 		// create enCode
 		function drawCont(){ 
 			var enCodes = Math.floor(Math.random()*26+65)
 			printCount = String.fromCharCode(enCodes);  
 			// printCount='*'
 			return printCount;
 		} 

 		// creat single span function
 		function creatCont(){
 			 $creatSnows = document.createElement('span') 
			 $creatSnows.setAttribute('class','snows')
			 $creatSnows.innerText=drawCont(); 
			 // $cont.appendChild($creatSnows);   //加入到大容器中
 			 return $creatSnows;
 		}

 		// 画每一个div盒子中的n个span标签
		function drawSpanList(){
			var snowsList = new Array();
			for (var i = 0; i < 6; i++) { 
				 creatCont();    
				 snowsList.push($creatSnows);
				 snowsList[i].style.color 
			}
			// console.log(snowsList.length);
			return snowsList;
		}


 		// create single divBox function 
		function createDivs(){  
			 var snowsList = drawSpanList();
			 // console.log(snowsList.length);
 			 $creatDivs = document.createElement('div')
 			 $creatDivs.setAttribute('class','divbox')
 			 $creatDivs.setAttribute('name','singlebox')
 			 for (var i = 0; i < snowsList.length; i++) {
 			 	$creatDivs.appendChild(snowsList[i]) 
 			 };
 			 return $creatDivs; 
			 // $cont.appendChild($creatDivs);  
			

 		}
	
	 	// 画n个div盒子
		function drawDivsList(){
			var divBoxList = new Array();
			for (var i = 0; i < cont; i++) { 
				 createDivs();    
				 divBoxList.push($creatDivs); 
			} 
			// console.log(divBoxList.length);
			return divBoxList;
		}
		
 
 		
 		 

	</script>
 		}
</body>
</html>
然后就是这个样子:
<img src="https://img-blog.csdn.net/20151216135356069?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值