js 小实例 随机出现小飞机
2016-03-10 16:57
591 查看
<!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>
相关文章推荐
- JavaScript制作简单的日历效果
- WeX5界面模块化的使用—JS引用
- Json转换中文到前台出现乱码问题
- Javascript定义类三种方法
- 关于javascript的this的几道题
- JS打印指定区域内容
- 弹窗 (居中 滚动)
- js滑动提示效果代码分享
- 一段简单的使用js在web页面中显示日期时间的代码
- 简单聊聊之JS的闭包问题
- 第五章:JavaScript中的数组
- 把map转换成String类型的json格式
- 纯js的excel导出插件
- JavaScript--V字
- js 字符串转换成数字
- 关于 js 的一些调试
- 解析json字符串并进行图片位置的替换
- js判断当前页面用什么浏览器打开的方法
- Jackson 框架,轻易转换JSON
- js时间格式