jquery 几行代码实现弹幕

<html>
<head>
    <title>Title</title>
    <style type="text/css">
        .div_class{
            background-color: aqua;
            width: 800px;
            height: 400px;

        }
        #img1 li{
            float: left;
        }
        #img1{
            width: 2000px;
        }

    </style>
    <script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var img1 = $("#img1 li");

            for(var i = 0; i < img1.length ; ++i){
                if (i%2 == 0)
                    img1.eq(i).css({width:"100px", height:"300px", backgroundColor:'#FFE1FF'})
                else
                    img1.eq(i).css({width:"300px", height:"300px", backgroundColor:'red'})
            }
            img1.mouseenter(function(){
                img1.stop()
                $(this).animate({width:700}).siblings().animate({width:200})
            }).mouseleave(function () {
                img1.animate({width:300})
                img1.stop()
            });

            var font_colors = ['white','grey','yellow','green']
            var text = $("#txt");
            var send_btn = $("#send_btn");

    //上面无视, 下面弹幕
            send_btn.click(function(){
                var span = $("<h2></h2>").text(text.val());
                span.css({
                    'color':font_colors[parseInt(Math.random() * font_colors.length)],
                    'left' : "800px",
                    'top' : parseInt(Math.random() * 300) +"px",
                    "position" : 'relative'
                });
                span.appendTo(img1.eq(1))
                span.animate({left:"-500px"},3000,"linear",function(){
                    $(this).remove()
                });


                text.val("")
            });

            text.keyup(function (e) {
                if ( e.keyCode == 13)
                    send_btn.click()
            });
 })


</script>
</head>

<body>
<div id = "img1" class="div_class">
    <ul>
        <li></li>
        <li></li>
        <li></li>
    </ul>
</div>
<textarea rows="2" cols="80" id="txt"></textarea>
    <button id="send_btn">发送</button>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值