HTML案例

arr.sort(function () {
 return Math.random()-0.5}
varr=Math.floor(Math.random()*30);
Math.floor(Math.random()*100);
Math.random()*100+50;
 function random(max,min) {return Math.random()*(max-min)+min; }
var arr2=[];
        for(var i=0;i<arr.length;i++){
           if(arr2.indexOf(arr[i])<0){
               arr2.push(arr[i]);
           }
        }

function randomColor() {
      var str="#";
      for(var i=0;i<3;i++){
           var col=Math.floor(Math.random()*256).toString(16);
            f(col.length<2){
                    col="0"+col;
                }
                str+=col;
            }
            return str;
        }

varscreenW=document.documentElement.clientWidth;
varscreenH=document..;
documentElement clientHeight

var div=document.getElementById("点击对象")
点击对象.addEventListener("click",clickHandler);
function clickHandler(e) {
  e=e || window.event;
   点击时的变化}
点击时找到数组里的元素
function clickHandler(e) {
            e=e || window.event;
            var index=arr.indexOf(this);
        }
侦听事件要清除this.removeEventListener
点击按钮随机添加div
document.body.innerHTML+="<button id='bn'>添加div</button>";
        var bn=document.getElementById("bn");
        bn.addEventListener("click",clickHandler);
        var i=0;
        function clickHandler(e) {
            e=e || window.event;
            addDiv();
            i++;
            bn=document.getElementById("bn");
            bn.addEventListener("click",clickHandler);
        }
        
        function addDiv() {
            document.body.innerHTML+="<div id='div"+i+"'></div>";
            var div=document.getElementById("div"+i);
            div.style.position="absolute";
            var w=randomWH();
            div.style.width=w+"px";
            div.style.height=w+"px";
            div.style.backgroundColor=randomColor();
            var position=getRandomPosition(w);
            div.style.left=position.left;
            div.style.top=position.top;
            console.log(position)
        }
        function randomColor(){
            var str="#";

            for(var i=0;i<3;i++){
               var col=Math.floor(Math.random()*256).toString(16);
                if(col.length<2){
                    col="0"+col;
                }
               str+=col;
            }
            return str;
        }

        function randomWH() {
            return Math.floor(Math.random()*350+50);
        }

        function getRandomPosition(w) {
            var position={};
            position.left=Math.floor(Math.random()*(document.documentElement.clientWidth-w))+"px";
            position.top=Math.floor(Math.random()*(document.documentElement.clientHeight-w))+"px";
            return position;
 按钮倒计时
<button id="bn" disabled>进入(10)</button>
   var i=9;
       var id=setInterval(animation,1000);
       var bn=document.getElementById("bn");
        function animation() {
            bn.innerHTML="进入("+i+")";
            i--;
            if(i<0){
                clearInterval(id);
                bn.innerHTML="进入";
                bn.disabled=false;
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值