zoukankan      html  css  js  c++  java
  • js 小实例 随机出现小飞机

    <!DOCTYPE html>
    <html>
    	<head>
    		<meta charset="UTF-8">
    		<title></title>
    		<script>
    			window.onload = function(){
    				document.body.bgColor = "black";
    				window.setInterval("str()",1000);
    			}
    			
    			function str()
    			{
    				var imgObj = document.createElement("img");
    				imgObj.setAttribute("src","img/1.jpg");
    				
    				//图片的随机大小
    				var width = getRandom(20,100);
    				imgObj.setAttribute("width",width);
    				
    				//位置
    				var x = getRandom(0,window.innerWidth);
    				var y = getRandom(0,window.innerHeight);
    				imgObj.setAttribute("style","position: absolute;left:"+x+"px;top:"+y+"px;")
    				
    				//点击的时候消失
    				imgObj.setAttribute("onclick","removeImg(this)");
    				document.body.appendChild(imgObj);
    				
    			}
    			
    			//随机数
    			function getRandom(min,max){
    				var random = Math.random()*(max - min)+min;
    				random = Math.floor(random);
    				return random;
    			}
    			//移除img
    			function removeImg(obj)
    			{
    				document.body.removeChild(obj);
    			}
    		</script>
    	</head>
    	<body>
    	</body>
    </html>
    

      

  • 相关阅读:
    Keyboarding题解
    埃及分数 解题报告
    小木棍加强版解题报告
    扩展欧几里得
    luoguP4999 烦人的数学作业
    中国剩余定理
    20201115gryz模拟赛解题报告
    扩展欧几里得算法
    斐蜀定理
    CSP2020-S游记
  • 原文地址:https://www.cnblogs.com/mingjixiaohui/p/5262569.html
Copyright © 2011-2022 走看看