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);
      }
  • 相关阅读:
    发布一个用于WinCE的矢量图控件
    [非原创]树和图的遍历
    对ZOJ第1146题的解答:LCDisplay
    [c#]可在任意位置弹出的BalloonTip
    windows程序开发中c++和c#的对照
    关于编译时的warning treated as error
    flyweight模式和图元几何变换
    i++和++i作为参数时的编译器处理方式分析~
    用小数数组计算E值(对ZOJ第1113题的解答)
    显示SendMessage和PostMessage的区别
  • 原文地址:https://www.cnblogs.com/juewuzhe/p/11765931.html
Copyright © 2011-2022 走看看