JQ实现弹幕效果


本文摘自PHP中文网,作者藏色散人,侵删。

JQ实现弹幕效果,快来吐糟你的想法吧

c86ca6b181b459829d39f8167aa2cbd.png代码如下,复制即可使用:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

<!DOCTYPE html>

<html>

    <head>

        <meta charset="utf-8" />

        <title>JQ实现弹幕效果</title>

        <style type="text/css">

            *{

                padding: 0;

                margin: 0;

            }

            #box{

                height:700px;

                width:1000px;

                margin: 0 auto;

                border:1px solid #000000;

                position: relative;

            }

            #main{

                width:100%;

                height:605px;

                position: relative;

                overflow: hidden;

            }

            p{

                position: absolute;

                left:1000px;

                width:200px;

                top:0;

            }

            #bottom{

                width:100%;

                height:80px;

                background: #ABCDEF;

                text-align: center;

                padding-top: 15px;

                position: absolute;

                left: 0;

                bottom: 0;

            }

            #txt{

                width:300px;

                height:50px;   

            }

            #btn{

                width:100px;

                height:50px;               

            }

        </style>

    </head>

    <body>

        <div id="box">

            <div id="main">

                 

            </div>

            <div id="bottom">

                <input type="text" id="txt" placeholder="请输入内容" />

                <input type="button" id="btn" value="发射" />

            </div>

        </div>

        <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>

        <script type="text/javascript">

            $(function(){

                var pageH=parseInt($("#main").height());

                var colorArr=["#cfaf12","#12af01","#981234","#adefsa","#db6be4","#f5264c","#d34a74"];               

                $("#btn").bind("click",auto);

                document.onkeydown=function(e){

                    if(e.keyCode == 13){

                        auto();

                    }

                };

                function auto(){

                    var $value = $("#txt").val();

                    $("#main").append("<p>" + $value + "</p>");

                    $("#txt").val("");

                    var _top=parseInt(pageH*(Math.random()));

                    var num=parseInt(colorArr.length*(Math.random()));

                    $("p:last-child").css({"top":_top,"color":colorArr[num],"font-size":"20px"});

                    $("p:last-child").animate({"left":"-200px"},10000);

                    $("p:last-child").stop().animate({"left":"-300px"},10000,"linear",function(){

                        $(this).remove();

                   });               

                    //console.log($value);

                };

                 

            })

        </script>

    </body>

</html>

更多编程相关内容,请关注php中文网编程入门栏目!

以上就是JQ实现弹幕效果的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

js如何实现简易计算器

为什么css放上面js放下面

如何利用js计算正方形的面积

js如何实现蒙版效果

详解js中图片懒加载的实现原理

typescript 和 javascript 的区别

浅谈js函数及闭包

一分钟了解js中int和string的转换(附代码)

js如何实现图片的懒加载

原生jsjs的区别是什么

更多相关阅读请进入《js》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...