创建一个小球

随机生成小球的大小
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script src="../new.js"></script>
<script>
    $('body').css("margin", "0")
        //随机生成小球的大小
    var whp = (Math.floor(Math.random() * 10) + 1) * 10;
    //创建一个小球
    var ball = $("<div></div>").css({
            width: whp + "px",
            height: whp + "px",
            // backgroundColor: "red",
            borderRadius: "50%",
            position: "relative",
            backgroundImage: "url(https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603947043746&di=7031bae21950e6f1383a7c9140c36525&imgtype=0&src=http%3A%2F%2Fimg.wxcha.com%2Ffile%2F201901%2F15%2F3b27e7bf0e.jpg)",
            backgroundSize: "100% 100%"
        })
        //将创建好的小球添加到body中
    $("body").append(ball);
    //获取浏览器窗口的宽高 计算小球移动的位置
    var h = $(window).innerHeight();
    h = h - whp;
    var w = $(window).innerWidth();
    w = w - whp;
    console.log(h, w)
    go();

    function go() {
        $('div').animate({
            left: w + "px",
            top: h + "px"
        }, 5000, function() {
            black();
        })
    }

    function black() {
        $('div').animate({
            left: 0,
            top: 0
        }, 5000, function() {
            go();
        })
    }
</script>

</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值