• vue 标题上下滚屏 无缝轮播


    参考网址:https://www.jianshu.com/p/b6813193ca0d

    <template>
      <div class="wrap" :style="{height:height + 'px'}">
        <div
          class="box"
          :style="{top: '-' + height + 'px', height: (height * actualMap.length) + 'px'}"
        >
          <div
            class="item"
            v-for="(item,index) in actualMap"
            :key="index"
            @click="showPreview(item)"
            :style="{'height':height + 'px','line-height':height + 'px'}"
          >
            <div
              class="inner_content"
              :style="{'line-height':height/2 + 'px'}"
            >{{item.rollTitle == "" ? item.title : item.rollTitle}}</div>
            <div
              class="amount_title"
              :style="{'line-height':height/2 + 'px'}"
            >{{item.pubTm|formatDate2}} · 浏览次数 {{item.viewCount}}</div>
          </div>
        </div>
      </div>
    </template>
     
    <script>
    export default {
      name: "selfCarousel", // 自定义标题栏走马灯
      props: {
        height: {
          default: 40,
          type: Number
        },
        contentArr: {
          default: [],
          type: Array
        }
      },
      data() {
        return {
          box: null,
          timer: undefined,
          moveTimer: undefined,
          index: 1
        };
      },
      computed: {
        actualMap: function() {
          let Tmp = this.contentArr
            ? JSON.parse(JSON.stringify(this.contentArr))
            : [];
          if (this.contentArr.length > 0) {
            Tmp.unshift(this.contentArr[this.contentArr.length - 1]);
            Tmp.push(this.contentArr[0]);
          }
          return Tmp;
        }
      },
      mounted() {
        this.box = document.getElementsByClassName("box")[0];
        this.inintTimer();
        let _this = this;
        $(".wrap").hover(
          function(e) {
            clearInterval(_this.timer);
            _this.timer = undefined;
          },
          function() {
            _this.inintTimer();
          }
        );
      },
      methods: {
        showPreview(row) {
          this.$emit("showPreview", row);
        },
        moveWidthIndex() {
          var l = this.index * -this.height - this.box.offsetTop;
          var count = 0;
          clearInterval(this.moveTimer);
          let self = this;
          this.moveTimer = setInterval(function() {
            count++;
            self.box.style.top =
              self.box.offsetTop + l / (self.contentArr.length * 2) + "px";
            if (count >= self.contentArr.length * 2) {
              clearInterval(self.moveTimer);
              self.box.style.top = self.index * - self.height + "px";
            }
          }, 20);
        },
        nextStep() {
          this.index++;
          if (this.index == this.actualMap.length) {
            this.index = 2;
            this.box.style.top = "-" + this.height + "px";
          }
          this.moveWidthIndex();
        },
        inintTimer() {
          let self = this;
          this.timer = setInterval(function() {
            self.nextStep();
          }, 2000);
        }
      }
    };
    </script>
     
    <style lang="less" scoped>
    .wrap {
       100%;
      position: relative;
      overflow: hidden;
    }
    .box {
       100%;
      position: absolute;
    }
    .item {
       100%;
    }
    .inner_content {
       100%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      font-size: 16px;
      color: #333333;
    }
    .amount_title {
      font-size: 14px;
      color: #999999;
    }
    </style>
  • 相关阅读:
    [C语言教程]八、数组
    [C语言教程]七、函数
    超炫的时间轴jquery插件Timeline Portfolio
    jQuery 鼠标滚轮插件 jquery.mousewheel.js
    js框架Modernizr是什么东西? 他是前端开发HTML5和CSS3的强有力前端js检测类库
    HTML模块化:使用HTML5 Boilerplate模板
    实践总结
    --@ui-router--登录页通过路由跳转到内页的demo
    --@angularjs-- $location.path('/login')-$location服务用法示例
    --@ui-router——$state服务原版详解
  • 原文地址:https://www.cnblogs.com/zhaomeizi/p/11960057.html
Copyright © 2020-2023  润新知