第四次作业Ⅱ(星星点灯)

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
        *{
            margin:0;
            padding:0;
        }
    </style>
</head>
<body>
<script>
    const img_w = 1019
    const img_h = 750
    document.body.style.backgroundColor = "black"
    window.onclick = function () {
        document.onclick = function (event) {

            let img = document.createElement("img")
            img.src = "https://www.desicomments.com/wp-content/uploads/2017/04/Stars-Giff.gif"
            
            img.style.position = "absolute"

            w = getRandom(50, 500)
            img.style.width = w+"px"
            h = w * img_h / img_w 
            img.style.height = h + "px"
            img.style.left = (event.pageX - w / 2) + "px"
            img.style.top = (event.pageY - h / 2) + "px"

            document.body.appendChild(img)
        }
    }
    function getRandom(min, max) {
        return min + Math.ceil((max - min) * Math.random())
    }
</script>
</body>
</html>

 

posted @ 2024-01-17 16:44  青鸢..i  阅读(13)  评论(0)    收藏  举报