美文网首页
vue、uniapp文字公告横向滚动

vue、uniapp文字公告横向滚动

作者: ciuhoi | 来源:发表于2020-11-27 10:42 被阅读0次

    vue文字横向滚动组件(取自GitHub)链接:https://github.com/wj704/vue-marquee-ho
    父组件引入:

    <template>
      <div id="app">
        <!-- <img src="./assets/logo.png"> -->
          <div class="marquee-wrap">
              <vue-marquee content="22222234343222" class="two"  showtwo="false"></vue-marquee>
          </div>
      </div>
    </template>
    
    <script>
    import vueMarquee from './Marquee.vue'
    
    export default {
      name: 'app',
      components: {
        vueMarquee
      }
    }
    </script>
    
    <style>
    .marquee-wrap {
      width: 375px;
      margin: 0 auto;
    }
    </style>
    

    横向滚动组件:Marquee

    <template>
        <div class="marquee-box">
            <div class="marquee-content" ref="out">
                <p :class="run?speed:''">
                    <span class="text1" ref="in" >{{content}}</span>
                    <span class="text2" v-if="showtwo||run">{{content}}</span>
                </p>
            </div>
        </div>
    </template>
    
    <script>
      export default {
        name: 'VueMarquee',
        data (){
          return{
            run: false,
            pWidth: '',
          }
        },
        props: {
          content: {
            default: "暂无公告内容",
            type: String
          },
          speed: {
            default: 'slow',
            type: String
          },
          showtwo: {
            default: true
          }
        },
        watch: {
            content (){
                var _this = this;
                setTimeout(()=>{
                    _this.$nextTick(()=>{
                        let out = _this.$refs.out.clientWidth;
                        let _in = _this.$refs.in.clientWidth;
                        _this.pWidth = 2*_in;
                        _this.run=_in>out?true:false;
                    });
                },0);
            }
        },
        mounted (){
            var _this = this;
            this.$nextTick(()=>{
                let out = _this.$refs.out.clientWidth;
                let _in = _this.$refs.in.clientWidth;
                _this.run=_in>out?true:false;
            });
        }
      }
    </script>
    <style lang="scss" scoped>
    @import "@ass/styles/color.scss";
        .marquee-box {
            height: 24px;
            line-height: 24px;
            color: $colorG;
            font-size: 12px;
        }
        .marquee-content{
            overflow: hidden;
            width:100%
        }
        .marquee-content p{
            display: inline-block;
            white-space: nowrap;
            margin: 0;
            font-size: 0;
        }
        .marquee-content span{
            display: inline-block;
            white-space: nowrap;
            padding-right: 300px;
            font-size: 12px;
        }
    
        .quick{
            -webkit-animation: marquee 5s linear infinite;
            animation: marquee 5s linear infinite;
        }
        .middle{
            -webkit-animation: marquee 8s linear infinite;
            animation: marquee 8s linear infinite;
        }
        .slow{
            -webkit-animation: marquee 25s linear infinite;
            animation: marquee 25s linear infinite;
        }
        @-webkit-keyframes marquee {
            0%  { -webkit-transform: translate3d(0,0,0); }
            100% { -webkit-transform: translate3d(-50%,0,0); }
        }
        @keyframes marquee {
            0%  { transform: translateX(0); }
            100% { transform: translateX(-50%);}
        }
    </style>
    

    uniapp文字公告横向滚动:
    横向滚动插件:https://ext.dcloud.net.cn/plugin?id=2553

    相关文章

      网友评论

          本文标题:vue、uniapp文字公告横向滚动

          本文链接:https://www.haomeiwen.com/subject/qgztwktx.html