zoukankan      html  css  js  c++  java
  • 点出漫天小星星

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html onclick="init(event)">
     <head>
      <title> new document </title>
      <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
      <script type="text/javascript">
            //点出漫天小星星
            //背景色
            //给html添加onclick事件
            //创建图片节点,并追加到body父节点下
            //图片的随机大小
            function init(e){
                    //创建图片节点(在内存中,还看不见)
                    var imgObj=document.createElement("img");
                    //追加节点
                    document.body.appendChild(imgObj);
                    //添加属性
                    imgObj.src="xingxing.gif";
                   //添加width属性
                   imgObj.width=getRandom(15,85);
                   //定位
                   var x=e.clientX? e.clientX : event.clientX;
                   var y=e.clientY? e.clientY : event.clientY;
                   imgObj.style.position="absolute";
                   imgObj.style.left=x - imgObj.width/2+"px";
                   imgObj.style.top=y- imgObj.width/2+"px";
            }
            function getRandom(min,max){
                    return Math.floor(Math.random()*(max-min)+min);
            }
      </script>
     </head>
     <body style="background-color:black" >
     </body>
    </html>
  • 相关阅读:
    关于git---远程
    关于git---主要
    css特效
    Canvas图片压缩
    TypeScript简单介绍
    html 常见兼容性问题及解决方法
    cookies,sessionStorage 和 localStorage 的区别
    vue-element-admin vue.config.js
    ② nodejs + mongodb 搭建服务器
    ① 数据自动填充
  • 原文地址:https://www.cnblogs.com/yangzailu/p/6098604.html
Copyright © 2011-2022 走看看