仿手机QQ的Javascript简易点赞功能

百般思念 提交于 2019-12-18 09:56:54
 var trigger = document.getElementById("trigger");
    var min = 100000;
    var max = 999999,count = 0;
    trigger.onclick = function () {
        var rect = document.createElement("div");
        var rad = Math.floor(Math.random() * (max - min) + min);
        /*产生随机颜色赋予div背景*/
        rect.id = "rect";
        rect.style.backgroundColor = "#" + rad;
        document.body.appendChild(rect);
        /*设置定时器,两秒后移除div节点*/
        setTimeout(function () {
            document.body.removeChild(rect);
        },2000);
        count++;
        if(count >=10){
            alert("today is enough...")
        }
    }

 

 
  #trigger{
            width: 25px;
            height: 25px;
            background-color: #008000;
            position: absolute;
            left: 500px;
            top: 300px;
        }
        #rect{
            width: 25px;
            height: 25px;
            background-color: #ed592c;
            position: absolute;
            left: 500px;
            top: 300px;
            animation: fly 2s ease-out;
        }
        @keyframes fly{
            70%{transform: translate(-20px,-150px) rotate(360deg); opacity:0.8;width: 40px;height: 40px}
            100%{transform: translate(-10px,-180px) rotate(540deg);opacity: 0;width: 50px;height: 50px}
        }

很简单的一段代码,html是一个id为trigger的div,效果是点击出现10个颜色不同的方块产生动画到消失,但是没有实现方块随机向上的哪个方向移动

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!