欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于vue實(shí)現(xiàn)8小時(shí)帶刻度的時(shí)間軸根據(jù)當(dāng)前時(shí)間實(shí)時(shí)定位功能

 更新時(shí)間:2023年05月16日 17:19:27   作者:小馨  
這篇文章主要介紹了基于vue實(shí)現(xiàn)8小時(shí)帶刻度的時(shí)間軸根據(jù)當(dāng)前時(shí)間實(shí)時(shí)定位功能,開(kāi)始時(shí)間、結(jié)束時(shí)間可配置,根據(jù)當(dāng)前時(shí)間初始化位置,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下

效果圖:

 需求:

1 開(kāi)始時(shí)間、結(jié)束時(shí)間可配置
2 時(shí)差固定8小時(shí)
3 根據(jù)當(dāng)前時(shí)間初始化位置
4 每隔5s刷新位置
5 超過(guò)結(jié)束時(shí)間停止刷新

HTML:

<div class="time-axis">
    <div class="startTime">{{start_time}}</div>
    <div class="endTime">{{end_time}}</div>
    <!-- 小時(shí)刻度 -->
    <div class="hourLine">
      <div class="line" v-for="index of 8" :key="index" :style="{left: `${90*(index-1)}px`}">
        <div class="secondLine">
          <div class="second" v-for="index of 4" :key="index" :style="{left: `${18*(index-1)}px`}"></div>
        </div>
      </div>
    </div>
    <!-- 指針 -->
    <div class="point" :style="{left: `${current_position}px`}" v-if="pointFlag">
      <div class="currentTime">{{current_time}}</div>
      <img src="@/assets/img/gateway/timeLine_point.png" alt="">
    </div>
  </div>

JS:

props: {
    start_time: {
      type: String,
      default: '',
    },
    end_time: {
      type: String,
      default: '',
    },
    currentTimeFromP: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      current_time: '10:00:00',
      allSecond: 0,
      st_second: '',
      et_second: '',
      current_second: '',
      current_position: '',
      timer: null,
      pointFlag: true,
    }
  },
  beforeDestroy() {
    if(this.timer) {
      clearInterval(this.timer); 
    }
  },
  mounted() {
    this.st_second = this.hmsToS(this.start_time)
    this.et_second = this.hmsToS(this.end_time)
    // 8小時(shí)總秒
    this.allSecond = this.hmsToS(this.end_time) - this.hmsToS(this.start_time)
    // 計(jì)算當(dāng)前位置
    this.current_position = this.bibliography() * 722
    // 判斷當(dāng)前時(shí)間是否超過(guò)結(jié)束時(shí)間或者小于開(kāi)始時(shí)間
    if(this.current_second>=this.et_second || this.current_second<this.st_second ) {
      this.$message.warning('當(dāng)前時(shí)間不在服務(wù)范圍內(nèi)')
      this.pointFlag = false
    } else {
      this.timer = setInterval(() => {
        if(this.current_second>=this.et_second || this.current_second<this.st_second ) {
          clearInterval(this.timer)
          this.$message.warning('當(dāng)前時(shí)間不在服務(wù)范圍內(nèi)')
          this.pointFlag = false
        }
        this.current_position = this.bibliography() * 722
      }, 5000)
    }
  },
  methods: {
    // 比例 = (當(dāng)前時(shí)間 - 開(kāi)始時(shí)間) / 總秒數(shù)
    bibliography() {
      // 當(dāng)前時(shí)間秒數(shù)
      this.current_second = this.hmsToS(this.nowDataToHMS())
      let key = (this.current_second - this.st_second) / this.allSecond
      return key
    },
    // 時(shí)分秒轉(zhuǎn)化秒
    hmsToS(e) {
      var time = e;
      var len= time.split(':')
      if(len.length==3){
        var hour = time.split(':')[0];
        var min = time.split(':')[1];
        var sec = time.split(':')[2];
        return  Number(hour*3600) + Number(min*60) + Number(sec);
      }
      if(len.length==2){
        var min = time.split(':')[0];
        var sec = time.split(':')[1];
        return Number(min*60) + Number(sec);
      }
      if(len.length==1){
        var sec = time.split(':')[0];
        return Number(sec);
      }
    },
    // 當(dāng)前時(shí)間時(shí)分秒
    nowDataToHMS() {
      let myDate = new Date()
      let str = myDate.toTimeString()
      this.current_time = str.substring(0,8)
      return this.current_time
    },
  },

CSS:

.time-axis {
  position: relative;
  height: 26px;
  border-left: 2px solid rgba(255,255,255,.6);
  border-right: 2px solid rgba(255,255,255,.6);
  width: 720px;
  background: rgba(0,0,0,.2);
  color: #fff;
  .startTime {
    position: absolute;
    top: -20px;
    left: -25px;
    color: #fff;
  }
  .endTime {
    position: absolute;
    top: -20px;
    right: -25px;
    color: #fff;
  }
  .hourLine {
    height: 70%;
    width: 100%;
    position: absolute;
    bottom: 0;
    display: flex;
    .line {
      position: absolute;
      width: 90px;
      height: 100%;
      border-right: 1px solid rgba(255,255,255,.6);
      &:nth-child(8) {
        border-right: none;
      }
      .secondLine {
        height: 50%;
        width: 100%;
        position: absolute;
        bottom: 0;
        display: flex;
        .second{
          position: absolute;
          width: 18px;
          height: 100%;
          border-right: 1px solid rgba(255,255,255,.3);
        }
      }
    }
  }
  .point {
    position: absolute;
    left: -8px;
    .currentTime {
      position: absolute;
      bottom: -10px;
      left: -18px;
      color: #00D4FF;
    }
    img {
      width: 16px;
      height: 46px;
    }
  }
}

到此這篇關(guān)于基于vue實(shí)現(xiàn)8小時(shí)帶刻度的時(shí)間軸根據(jù)當(dāng)前時(shí)間實(shí)時(shí)定位功能的文章就介紹到這了,更多相關(guān)vue帶刻度時(shí)間軸內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 基于Vue實(shí)現(xiàn)消息提示功能

    基于Vue實(shí)現(xiàn)消息提示功能

    這篇文章主要為大家詳細(xì)介紹了如何基于Vue實(shí)現(xiàn)簡(jiǎn)單的消息提示功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-10-10
  • vue路由第二次進(jìn)入頁(yè)面created和mounted不執(zhí)行問(wèn)題及解決

    vue路由第二次進(jìn)入頁(yè)面created和mounted不執(zhí)行問(wèn)題及解決

    這篇文章主要介紹了vue路由第二次進(jìn)入頁(yè)面created和mounted不執(zhí)行問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • vue:el-input輸入時(shí)限制輸入的類型操作

    vue:el-input輸入時(shí)限制輸入的類型操作

    這篇文章主要介紹了vue:el-input輸入時(shí)限制輸入的類型操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-08-08
  • 解決echarts中橫坐標(biāo)值顯示不全(自動(dòng)隱藏)問(wèn)題

    解決echarts中橫坐標(biāo)值顯示不全(自動(dòng)隱藏)問(wèn)題

    這篇文章主要介紹了解決echarts中橫坐標(biāo)值顯示不全(自動(dòng)隱藏)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-07-07
  • Vue3解決Mockjs引入后并訪問(wèn)404(Not Found) 的頁(yè)面報(bào)錯(cuò)問(wèn)題

    Vue3解決Mockjs引入后并訪問(wèn)404(Not Found) 的頁(yè)面報(bào)錯(cuò)問(wèn)題

    mock.js:是一款模擬數(shù)據(jù)生成器,可以生成隨機(jī)數(shù)據(jù),攔截 Ajax 請(qǐng)求,使用mockjs模擬后端接口,可隨機(jī)生成所需數(shù)據(jù),模擬對(duì)數(shù)據(jù)的增刪改查,本文給大家介紹了Vue3解決Mockjs引入后并訪問(wèn)404(Not Found) 的頁(yè)面報(bào)錯(cuò)問(wèn)題,需要的朋友可以參考下
    2025-04-04
  • vue制作加載更多功能的正確打開(kāi)方式

    vue制作加載更多功能的正確打開(kāi)方式

    這篇文章是一篇Vue.js的教程,目標(biāo)在于用一種常見(jiàn)的業(yè)務(wù)場(chǎng)景——分頁(yè)/無(wú)限加載,以及編寫過(guò)程中自己的錯(cuò)誤寫法,分享給大家,幫助讀者更好的理解Vue.js中的一些設(shè)計(jì)思想。
    2016-10-10
  • vue @ ~ 相對(duì)路徑 路徑別名設(shè)置方式

    vue @ ~ 相對(duì)路徑 路徑別名設(shè)置方式

    這篇文章主要介紹了vue @ ~ 相對(duì)路徑 路徑別名設(shè)置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • Vue keep-alive組件的使用及如何清除緩存

    Vue keep-alive組件的使用及如何清除緩存

    本文介紹了Vue keep-alive組件的使用及如何清除緩存,給大家分享清除緩存的幾種方法,結(jié)合實(shí)例代碼給大家講解的非常詳細(xì),需要的朋友跟隨小編一起看看吧
    2023-10-10
  • 淺談vux之x-input使用以及源碼解讀

    淺談vux之x-input使用以及源碼解讀

    這篇文章主要介紹了淺談vux之x-input使用以及源碼解讀,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-11-11
  • Vue項(xiàng)目打包并部署nginx服務(wù)器的詳細(xì)步驟

    Vue項(xiàng)目打包并部署nginx服務(wù)器的詳細(xì)步驟

    vue項(xiàng)目開(kāi)發(fā)好之后需要部署到服務(wù)器上進(jìn)行外網(wǎng)訪問(wèn),下面這篇文章主要給大家介紹了關(guān)于Vue項(xiàng)目打包并部署nginx服務(wù)器的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-07-07

最新評(píng)論