js实现垂直向上滚动

效果图:

代码如下


<!--
 * @Descripttion: 
 * @version: 
 * @Author: yang_ft
 * @Date: 2020-09-30 14:08:07
 * @github: famensaodiseng
 * @LastEditTime: 2020-10-12 09:14:59
-->
<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>垂直滚动</title>
  <!-- <link rel="shortcut icon" href="favicon.ico"> -->
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    ul li {
      list-style: none;
    }

    .organization {
      width: 300px;
      height: 150px;
      border: 1px solid #000;
      overflow: hidden;
      padding: 20px;
      box-sizing: border-box;
    }

    .org li {
      border-bottom: 1px dashed #ccc;
    }
  </style>
</head>

<body>
  <div class="organization" id="organization">
    <div class="org" id="org">
      <ul>
        <li>1111111111111</li>
        <li>2222222222222</li>
        <li>3333333333333</li>
        <li>4444444444444</li>
        <li>5555555555555</li>
        <li>6666666666666</li>
        <li>7777777777777</li>
        <li>8888888888888</li>
      </ul>
    </div>
    <div class="org" id="org1">
    </div>
  </div>
  <script>
    var speed = 70
    org1 = document.getElementById("org1");
    org1.innerHTML = org.innerHTML
    function Marquee() {
      if (org1.offsetTop - organization.scrollTop <= 0)
        organization.scrollTop -= org.offsetHeight
      else {
        organization.scrollTop++
      }
    }
    var MyMar = setInterval(Marquee, speed)
    organization.onmouseover = function () { clearInterval(MyMar) }
    organization.onmouseout = function () { MyMar = setInterval(Marquee, speed) } 
  </script>
</body>

</html>
posted @ 2020-10-12 09:23  小茴香  阅读(906)  评论(0编辑  收藏  举报
Live2D