zoukankan      html  css  js  c++  java
  • JS 无缝跑马灯

    无缝跑马灯

    • 把内容复制一份一模一样的放在后面
    • 当conEnd的开头运动到外层盒子开头的时候, 让scrollLeft瞬间设置为0, 即scrollLeft的值为 conBegin的盒子宽度
    代码
    <!--
     * @Author: lemon
     * @Date: 2020-09-13 18:39:32
     * @LastEditTime: 2020-09-13 20:00:32
     * @LastEditors: Please set LastEditors
     * @Description: In User Settings Edit
     * @FilePath: React前端准备JS基础跑马灯.html
    -->
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <style type="text/css">
          * {
            margin: 0;
            padding: 0;
            font-family: "5FAE8F6F96C59ED1", Helvetica, sans-serif;
            font-size: 14px;
            -webkit-user-select: none;
          }
          #box {
            margin: 50px auto;
            padding: 0 10px;
             1000px;
            height: 35px;
            line-height: 35px;
            border: 5px soild lightgreen;
            background-color: lightsalmon;
            float: left;
          }
          #box {
            white-space: nowrap;
            overflow: hidden;
          }
          #warp div {
            display: inline-block;
          }
          #box div span {
            color: red;
            font-weight: bold;
            font-size: 16px;
          }
        </style>
      </head>
      <body>
        <div id="box">
          <div id="warp">
            <div id="conBegin">
              <span>通知:</span>
              要得到你必须要付出,要付出你还要学会坚持,如果你真的觉得很难,那你就放弃,但是你放弃了就不要抱怨,我觉得人生就是这样,世界是公平的,每个人都是通过自己的努力,去决定自己生活的样子
            </div>
            <div id="conEnd">
              <span>通知:</span>
              要得到你必须要付出,要付出你还要学会坚持,如果你真的觉得很难,那你就放弃,但是你放弃了就不要抱怨,我觉得人生就是这样,世界是公平的,每个人都是通过自己的努力,去决定自己生活的样子
            </div>
          </div>
        </div>
      </body>
    <script type="text/javascript">
        var box = document.getElementById("box");
        var conBegin = document.getElementById("conBegin");
        var warp = document.getElementById("warp");
        function move() {
          var curLeft = box.scrollLeft;
          var conBegin_width = parseInt(
            window.getComputedStyle(conBegin, null).width
          );
          box.scrollLeft = curLeft + 1;
          lastLeft = box.scrollLeft;
          if (curLeft > conBegin_width) {
            console.log(curLeft);
            box.scrollLeft = 0;
          }
        }
        var timer = window.setInterval(move, 10);
        box.onmouseover = function () {
          window.clearInterval(timer);
        };
        box.onmouseout = function () {
          timer = window.setInterval(move, 10);
        };
      </script>
    </html>
    
  • 相关阅读:
    python txt文件数据转excel
    数字的可视化:python画图之散点图sactter函数详解
    Python使用matplotlib模块绘制多条折线图、散点图
    python 读取文件时报错UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 205: illegal multibyte sequence
    Python Requests post并将得到结果转换为json
    Python按行读取文件、写文件
    重装系统后,指纹识别无法使用
    MySQL的简单使用和JDBC示例
    resin后台输出中文乱码的解决办法!
    MySQL时间增加、字符串拼接
  • 原文地址:https://www.cnblogs.com/xiaoxu-xmy/p/13662870.html
Copyright © 2011-2022 走看看