美文网首页
vue 不是很完美的标尺

vue 不是很完美的标尺

作者: 0000000asdasd | 来源:发表于2019-06-29 07:18 被阅读0次
捕获7.JPG
// 放入全局样式表中
.intNum {
  border-left: 1px solid black;
  height: 20px;
  position: relative;
}
.floatNum {
  border-left: 1px solid black;
  height: 10px;
}
.tishi {
  position: absolute;
  bottom: 30px;
  right: 0;
  font-size: 12px;
  -moz-user-select: none;
  -khtml-user-select: none;
  user-select: none;
}
.hiddenDiv{
  width: 1px;
}

<template>
  <div class="content">
    <div class="jiantou">
      <span class="top"></span>
      <span class="line"></span>
    </div>
    <el-input class="input" @input="changeScaleplate" v-model="msg" placeholder type="number"></el-input>
    <section id="zhizi"></section>
  </div>
</template>

<script>
export default {
  name: "HelloWorld",
  data() {
    return {
      msg: 0,
      mouseX: 0,
      mouseFirst: true,
      defaultAmount: 1000,
      leftAmount: 0,
      rightAmount: 0,
      step: 30,
      setTimeOut: null
    };
  },
  mounted() {
    let _this = this;
    let box = document.getElementById("zhizi");
    this.leftAmount = this.defaultAmount - this.step;
    this.rightAmount = this.defaultAmount + this.step + 1;
    this.msg = this.defaultAmount;
    this.createScaleplate();
    box.ontouchmove = function(e) {
      _this.toSlide(e);
    };
  },
  methods: {
    changeScaleplate() {
      setTimeout(() => {
        let box = document.getElementById("zhizi");
        box.innerHTML = "";
        this.msgs = Math.ceil(Number(this.msg));
        this.leftAmount = this.msgs - this.step;
        this.rightAmount = this.msgs + this.step + 1;
        this.createScaleplate();
      },300);
    },
    createScaleplate() {
      let box = document.getElementById("zhizi");
      for (let i = this.leftAmount; i < this.rightAmount; i++) {
        let div = document.createElement("div");
        div.setAttribute("id", i);
        if (i % 10 === 0 && i >= 0) {
          div.setAttribute("class", "intNum");
          let span = document.createElement("span");
          span.setAttribute("class", "tishi");
          span.innerText = i;
          div.appendChild(span);
        } else if (i >= 0) {
          div.setAttribute("class", "floatNum");
        } else {
          div.setAttribute("class", "hiddenDiv");
        }
        box.appendChild(div);
      }
    },
    toLeftSlide(BX) {
      let box = document.getElementById("zhizi");
      box.removeChild(box.firstChild);
      let lastChildId = Number(box.lastChild.getAttribute("id"));
      let div = document.createElement("div");
      div.setAttribute("id", lastChildId + 1);
      if ((lastChildId + 1) % 10 === 0) {
        div.setAttribute("class", "intNum");
        let span = document.createElement("span");
        span.setAttribute("class", "tishi");
        span.innerText = lastChildId + 1;
        div.appendChild(span);
      } else {
        div.setAttribute("class", "floatNum");
      }
      this.mouseX = BX;
      this.leftAmount = Number(box.firstChild.getAttribute("id"));
      this.rightAmount = Number(box.lastChild.getAttribute("id"));
      this.msg = Number(box.lastChild.getAttribute("id")) - (this.step - 1);
      box.appendChild(div);
    },
    toRightSlide(BX) {
      let box = document.getElementById("zhizi");
      let firstChildId = Number(box.firstChild.getAttribute("id"));
      if (firstChildId === -this.step) {
        return false;
      }
      box.removeChild(box.lastChild);
      let div = document.createElement("div");
      div.setAttribute("id", firstChildId - 1);
      if ((firstChildId - 1) % 10 === 0 && firstChildId - 1 >= -1) {
        div.setAttribute("class", "intNum");
        let span = document.createElement("span");
        span.setAttribute("class", "tishi");
        span.innerText = firstChildId - 1;
        div.appendChild(span);
      } else if (firstChildId - 1 >= 0) {
        div.setAttribute("class", "floatNum");
      } else {
        div.setAttribute("class", "hiddenDiv");
      }
      this.mouseX = BX;
      this.leftAmount = Number(box.firstChild.getAttribute("id"));
      this.rightAmount = Number(box.lastChild.getAttribute("id"));
      this.msg = Number(box.lastChild.getAttribute("id")) - this.step;
      box.prepend(div);
    },
    toSlide(e) {
      let _this = this;
      let box = document.getElementById("zhizi");
      if (_this.mouseFirst) {
        _this.mouseX = e.changedTouches[0].clientX;
        _this.mouseFirst = false;
      }
      let AX = _this.mouseX;
      let BX = e.changedTouches[0].clientX;
      if (AX - BX > 0) {
        _this.toLeftSlide(BX);
      } else if (AX - BX < 0) {
        _this.toRightSlide(BX);
      }
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.content {
  width: 300px;
  height: 400px;
  border: 1px solid black;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  position: relative;
}
.input {
  width: 200px;
  margin-bottom: 20px;
}
.jiantou {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.top {
  border: 10px solid #ccc;
  border-left-color: transparent;
  border-top-color: transparent;
  border-right-color: transparent;
}
.line {
  border-left: 1px solid #ccc;
  height: 60px;
}
#zhizi {
  display: flex;
  justify-content: space-between;
  width: 100%;
  height: 50px;
  align-items: flex-end;
  overflow: hidden;
}
.intNum {
  border-left: 1px solid black;
  height: 20px;
}
.floatNum {
  border-left: 1px solid black;
  height: 10px;
}
</style>

相关文章

  • vue 不是很完美的标尺

  • 你不是标尺

    “你怎么这么笨,这么简单的题都不会。” 孩子什么也没说,只是低着头,呆呆地看着数学题。 妈妈又将刚才的讲解复读机一...

  • 爱终于开了花

    今天终于清醒了:我不是全能的,我不是完美的,我不是全对的,而这些年我用这样一把唯我独尊的标尺对爱我的人和我爱...

  • Vue<滑动标尺>

    找了很多资料,发现这类的很少,而且很多的兼容性不好。这个可以在PC端以及移动端使用,但是用起来需要引用外部js。(...

  • 星空

    不是很完美的星空

  • 【Axure10】菜单-视图-标尺、网格、辅助线

    显示标尺 控制标尺的显示与隐藏。 标尺:用于页面中距离尺寸的参考。 显示标尺可以通过鼠标在标尺范围内拖出页面参考线...

  • vue学习第一天笔记

    VUE 下载和安装vue官网npm下载vue模块:npm install vue下载完后使用里面的vue.js文件...

  • 标尺与参考线 | Adobe Illustrator 从入门到精

    1. 怎么打开标尺? 方法1:视图 > 标尺> 显示标尺 方法2:直接按 Ctrl + R 2. 怎么改变标尺单位...

  • 走开,我要开始装b了

    在文学艺术上,一定有一个界限,是划分经典与庸俗的标尺。 这个标尺不是思想的深刻,也不是文字的造诣,而应该是真诚。几...

  • webpack3-配置vue

    安装vue,因为后续在项目中也会使用vue,所以并不是开发时依赖 我们在编译完后会出现如下错误: 这是因为runt...

网友评论

      本文标题:vue 不是很完美的标尺

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