zoukankan      html  css  js  c++  java
  • Taro -- 文字左右滚动公告效果

    文字左右滚动公告效果

    设置公告的左移距离,不断减小,当左移距离大于公告长度(即公告已移出屏幕),重新循环。

     <View className='scroll-wrap'>
        <View className='scroll ovh font28 relative'>
           <View className="marquee_text" style={{left: this.state.marqueeDistance + 'px'}}>
              {this.state.notice}
           </View>
        </View>
     </View>
    .scroll-wrap{
      background:#FF3766;
      padding:10px 70px 10px 0;
      height:50px;
      line-height: 50px;
    }
    .ovh{
      overflow:hidden;
    }
    .font28{
      font-size:28px;
    }
    .relative{
      position:relative;
    }
    .scroll{
      color:#fff;
      100%;
      height:40px;
    }
    .marquee_text {
      white-space: nowrap;
      position: absolute;
      top: 0;
    }
    this.state = ({
          length:0,
          windowWidth:0,
          notice:'哈哈哈哈哈哈,我是滚动的公告,我是滚动的公告!',
          marqueePace: 1,//滚动速度
          marqueeDistance: 10,//初始滚动距离
          size: 12,
          countTime: ''
    })
      componentWillMount() {
        let length = this.state.notice.length * this.state.size;//文字长度
        let windowWidth = Taro.getSystemInfoSync().windowWidth; // 屏幕宽度
        console.log(windowWidth);
        this.setState({
          length:length,
          windowWidth:windowWidth,
          marqueeDistance: windowWidth
        },() => {
          this.run();
        })
      }
     
    
    
      run = (e) => {
          let countTime = setInterval(() => {
            if(-this.state.marqueeDistance < this.state.length){
              let newMarquee = this.state.marqueeDistance - this.state.marqueePace;
              this.setState({
                marqueeDistance : newMarquee
              })
            }else{
              this.setState({
                marqueeDistance:this.state.windowWidth
              })
              this.run();
              clearInterval(countTime);
            }
          }, 20);
      }
  • 相关阅读:
    JMeter学习(二十三)关联
    最常用的DOS命令
    不同类型的操作系统
    分级存储管理的四大优点
    软件工程中数据库设计
    PPP(点对点协议(Point to Point Protocol)
    关键路径法
    什么是鲁棒性测试
    何为蠕虫病毒
    临界区
  • 原文地址:https://www.cnblogs.com/juewuzhe/p/11765931.html
Copyright © 2011-2022 走看看