zoukankan      html  css  js  c++  java
  • requestAnimationFrame 实现跑马灯

    html :

    <!-- 公告 -->
            <div class="notice-container" v-show="noticeList.length">
              <span class="notice-icon"></span>
              <div class="notice-items" ref="noticeBox">
                <div class="notice-items-inner" ref="noticeInner">
                  <p v-for="(item, index) in noticeList" :key="index">{{item.noticeContent}}</p><p>{{noticeList.length && noticeList[0].noticeContent}}</p> // 两p标签必须粘合一起
                </div>
              </div>
            </div>
    

    js:

    // 公告的走马灯
        initNoticeScroll () {
          let boxWidth = this.$refs.noticeBox.offsetWidth
          let innerWidth = 0
          let child = this.$refs.noticeInner.childNodes
          child.forEach(item => {
            innerWidth += item.offsetWidth
          })
          innerWidth += boxWidth * (child.length - 1)
          if (innerWidth > boxWidth) {
            let padding = 0
            let animation = () => {
              padding -= 1
              this.$refs.noticeInner.style.cssText = `transform: translate3d(${padding}px, 0, 0)`
              if (padding === -(innerWidth - child[0].offsetWidth)) {
                padding = 0
                this.$refs.noticeInner.style.cssText = `transform: translate3d(${padding}px, 0, 0)`
              }
              requestAnimationFrame(animation)
            }
            animation()
          }
        },

    css:

    .notice-container {

    opacity: 0.6;
    background: #141F33;

          font-size: 12px;
          color: #3E4759;
          height: 30px;
          overflow: hidden;
          box-sizing: border-box;
           100%;
          display: flex;
          align-items: center;
          position: relative;
        color:#fff;
          .notice-icon {
            display: block;
            margin-left: 10px;
            flex-shrink: 0;
             27px;
            height: 27px;
            background: url("../assets/home/icon_home_gg.png") no-repeat;
            background-size: 100% 100%;
          }
    
          .notice-items {
            margin: 0 0 0 6px;
            flex: 1;
            display: flex;
            overflow: hidden;
            height: 30px;
    
            .notice-items-inner {
              display: flex;
              align-items: center;
               100%;
    
              p {
                flex-shrink: 0;
                margin-right: 100%;
                white-space: nowrap;
              }
            }
          }
        }

    效果:

    注销、停止动画:https://www.cnblogs.com/jiangxiaobo/p/5943755.html

  • 相关阅读:
    django admin site配置(二)
    MyEclipse中无法将SVN检出来的项目部署到tomcat中
    遍历目录树,清理编译目录
    axis2学习, ant 构建axis2 ws
    [置顶] 2013 Multi-University Training Contest 8
    Cocos2d-x 关于在iOS平台真机测试的一些注意
    SharePoint 2013的100个新功能之社交
    路由共享上网原理
    red ant
    nginx正向代理访问百度地图API
  • 原文地址:https://www.cnblogs.com/wilsunson/p/12123677.html
Copyright © 2011-2022 走看看