• 弹幕和回到顶部前端web


    弹幕和回到顶部前端web

    弹幕

    1.效果演示

    ceshi.gif

    2.相关代码
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>弹幕</title>
        <script src="../jquery-1.9.1/jquery-1.9.1/jquery.js"></script>
        <style>
            *{
                margin: 0;
                padding: 0;
            }
    
            img {
    
                 50px;
                height: 50px;
    
            }
    
            .bottom {
                 100%;
                height: 80px;
                position: fixed;
                bottom: 0px;
                border: 1px solid black;
                z-index: 99;
    
            }
    
            .inner {
    
                position: absolute;
                margin-top: 15px;
                margin-left: 625px;
            }
    
            .in {
                 300px;
                height: 30px;
            }
    
            .te {
                margin-top: -45px;
                margin-left: 68px;
            }
    
            .box {
                 100%;
                height: 100%;
                border: 1px solid red;
                position: absolute;
                overflow: hidden;
            }
    
            .test{
                font-size: 20px;
                position: relative;
                /*left: 1000px;*/
                /*top: 300px;*/
    
            }
    
        </style>
    </head>
    <body>
    
    <div class="box"><span class="test">文字啊</span> </div>
    <!--弹幕-->
    <div class="bottom">
        <div class="inner">
            <img src="images/弹幕.jpg">
            <div class="te">
                <input id="txt" class="in" type="text" placeholder="请输入弹幕">
                <input type="button" value="发出">
            </div>
        </div>
    </div>
    <script>
        $(function () {
    
            $("input[type='button']").click(function () {
                var colors = ["red","yellow","blue","black","orange","pink"];
                var co = parseInt(Math.random()*colors.length);
    
                console.log($(".in").val());
                var hi = parseInt((Math.random()*400)+20);
                console.log(hi);
                var inVal = $(".in").val();
                $("<span></span>").text(inVal)
                    .addClass("test")
                    .css("color",colors[co])
                    .css("left","1000")
                    .css("top",hi)
                    .animate({left:-100},10000,"linear",function () {
                        $(this).remove();
                    })
                    .appendTo($(".box"))
                ;
               $("#txt").val("");
            });
    
    
            $(window).keyup(function (e) {
                if (e.keyCode == 13){
                    $("input[type='button']").click();
                }
    
    
            });
    
    
        })
    
    
    </script>
    
    </body>
    </html>
    

    2.回到顶部

    1.效果演示

    top.gif

    2.相关代码
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <script src="../jquery-1.9.1/jquery-1.9.1/jquery.js"></script>
    
        <style>
            div{
                 100%;
                height: 3000px;
    
            }
            a{
                top: 500px ;
                left: 1400px;
                position: fixed;
                display: block;
                 51px;
                height: 103px;
                background: url("images/top.jpg") no-repeat -149px -96px ;
                /*border: 1px solid red;*/
                overflow: hidden;
                cursor: pointer;
            }
            a:hover{
                background: url("images/top.jpg") no-repeat -236px -96px ;
    
    
            }
    
        </style>
    </head>
    <body>
    <!--返回top的图片-->
    <a id="top"></a>
    <div></div>
    
    
    
    <script>
    
    
        $(window).scroll(function () {
    
            console.log($(window).scrollTop());
           var to =  $(window).scrollTop();
          if(to>=1500){
              $("#top").fadeIn(200);
          }else {
              $("#top").fadeOut(200);
          }
        });
    
        $("#top").click(function () {
            $("html,body").animate({scrollTop:0},1000);
        });
    
    
    </script>
    
    </body>
    </html>
    
  • 相关阅读:
    【Git教程】Git教程之分支管理
    【Git教程】Git教程及使用命令
    【深入理解Java虚拟机】自动内存管理机制——垃圾回收机制
    HDU-5902-GCD is Funny解题笔记
    数据结构——二叉树的遍历
    数据结构——树
    Css--input输入框点击时去掉外框outline:medium;(chrome)
    JSON中eval与parse的区别
    【转载】实时监听输入框值变化的完美方案:oninput & onpropertychange
    使用寄存器点亮LED(第2节)—寄存器映射代码讲解
  • 原文地址:https://www.cnblogs.com/charlypage/p/9723407.html
Copyright © 2020-2023  润新知