jquery点赞效果

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script type="text/javascript" src="js/jquery-1.11.1.js"></script>
    <style type="text/css">
    input{
        width: 200px;
        height: 50px;
        background: bisque;
        color: #fff;
        font-size: 20px;
        font-weight: bold;
        position: absolute;
        bottom: 100px;
        left: 50%;
    }
    img{
        width: 20px;
        height: 20px;
        position: absolute;
        bottom: 100px;
        left: 50%;
        margin-left: -10px;

    }


    </style>
    <script type="text/javascript">
    $(function(){
        //1.找到按钮添加事件
        $("#btn").click(function(){
        //2.生成彩色的心(难点:随机生成不同颜色的心)
        var num=Math.floor(Math.random()*3+1);
        var index=$("#content").children("img").length;//0
        
        //3.把生成好的彩色的心追加到页面上
        $('#content').append("<img src=''/>");
        $("img:eq("+index+")").attr("src","xin/"+num+".png");
        
        //4.让彩色的心动起来(怎么心随心所欲的动起来)
        //随机位置 
        var rand=parseInt(Math.random()*900);
        $("img").animate({
            bottom:"800px",
            opacity:"0",
            left:rand


        },3000)


        })
    
        


    })


    </script>
</head>
<body>
    <div id="content"></div>
    
    <input type="button" id="btn" class="btn" value="赞赞赞赞赞">
    
</body>
</html>

转载于:https://my.oschina.net/kitty0107/blog/1633076

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值