弹幕案例

样式
    <style>
        html, body {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100%;
            font-size: 62.5%;
        }

        .boxDom {
            width: 100%;
            height: 100%;
            position: relative;
            overflow: hidden;
        }

        .idDom {
            width: 100%;
            height: 24%;
            background: #666;
            position: fixed;
            bottom: 0px;
        }

        .content {
            width: 430px;
            height: 40px;
            display: inline-block;
            position: absolute;
            top: 0px;
            left: 0px;
            bottom: 0px;
            right: 0px;
            margin: auto;
            z-index: 100;
        }

        .title {
            display: inline;
            font-size: 4em;
        }
        span {
            position: absolute;
            font-size: 20px;
            width: 500px;
            color: Magenta;
        }
    </style>
<script src="js/jquery-3.2.1.js"></script> 
 //引入jQuery库

    <script>
        $(function () {
               $('.btn').click(function () {
                   var randomY = Math.random()*400;
                   $('<span></span>').text($('.text').val())
                           .css({
                               left:1370,
                               color:'green',
                               top:randomY
                           })
                           .animate({left:-500},30000,function () {
                               $(this).remove();
                           })
                           .appendTo('.boxDom');
                    $('.text').val('');
               });
            $('.text').keydown(function (ev){
                if(ev.keyCode == 13){
                    $('.btn').click();
                }
            })
        });
    </script>
        //html部分
<body>
<div class="boxDom">
    <div class="idDom" id="idDom">
        <div class="content">
            <p class="title">吐槽:</p>
            <input type="text" id="text" class="text" autofocus/>
            <input type="button" id="btn" class="btn" value="发布"/>
        </div>
    </div>
</div>
</body>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值