最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue如何拖動(dòng)滑塊

 更新時(shí)間:2024年07月27日 09:55:22   作者:三次元挨踢汪  
這篇文章主要介紹了Vue如何拖動(dòng)滑塊問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Vue拖動(dòng)滑塊

拖動(dòng)進(jìn)度條

  • Vue
div頁面數(shù)據(jù)樣式
 <div class="bg">
              <p class="txt0">0</p>
              <i class="A" :style="{ width: Avalue + '%' }">
                <p class="Aptxt">A:{{ Avalue }}</p>
              </i>

              <i class="B" :style="{ width: Bvalue + '%' }">
                <p class="Bptxt">B:{{ Bvalue }}</p>
              </i>

              <i class="C" :style="{ width: Cvalue + '%' }">
                <p class="Cptxt">C:{{ Cvalue }}</p>
              </i>
              <p class="txt100">100</p>
              <span
                class="btnA"
                :style="{ left: positionX_A + 'px' }"
                @mousedown="moveA"
              ></span>
              <span
                class="btnB"
                :style="{ left: positionX_B + 'px' }"
                @mousedown="moveB"></span>
              <span
                class="btnC"
                :style="{ left: positionX_C + 'px' }"
                @mousedown="moveC"
              ></span>
            </div>
  • data數(shù)據(jù)
  Avalue: 0,
      Bvalue: 0,
      Cvalue: 0,
      positionX_A: 0,
      positionX_B: 0,
      positionX_C: 0,
  //接口返回的數(shù)據(jù)
       mormal_level: null,
        minor_level: null,
        major_level: null,

監(jiān)聽事件的發(fā)生改變時(shí)改變對(duì)應(yīng)的數(shù)值

  watch: {
    templateIndex(val) {
      this.index = val ? val : 0;
    },
    positionX_A(val) {
      this.Avalue = Math.ceil(((val + 10) / 435) * 100);
    },
    positionX_B(val) {
      this.Bvalue = Math.ceil(((val + 10) / 435) * 100);
    },
    positionX_C(val) {
      this.Cvalue = Math.ceil(((val + 10) / 435) * 100);
    },
  },

查詢時(shí)重新給賦值到滑塊上

//該方法主要用于后端返回?cái)?shù)據(jù)分別賦給的Avalue,Bvalue,Cvalue,之后重新計(jì)算樣式寬度
 //可以不用調(diào)
 setPosition() {
      this.positionX_A = parseInt((this.Avalue / 100) * 435 - 10);
      this.positionX_B = parseInt((this.Bvalue / 100) * 435 - 10);
      this.positionX_C = parseInt((this.Cvalue / 100) * 435 - 10);
    },
//移動(dòng)滑塊時(shí)的方法
    moveA(e) {
      let odiv = e.target; //獲取目標(biāo)元素
      console.log(e,'測(cè)試數(shù)據(jù)')
      //算出鼠標(biāo)相對(duì)元素的位置
      let disX = e.clientX - odiv.offsetLeft;
      document.onmousemove = (e) => {
        let left = e.clientX - disX;
        if (left <= this.positionX_B && left >= -10 && left <= 425) {
          this.positionX_A = left;
          odiv.style.left = left + "px";
        }
      };
      document.onmouseup = (e) => {
        document.onmousemove = null;
        document.onmouseup = null;
      };
    },
    moveB(e) {
      let odiv = e.target; //獲取目標(biāo)元素
      //算出鼠標(biāo)相對(duì)元素的位置
      let disX = e.clientX - odiv.offsetLeft;
      document.onmousemove = (e) => {
        let left = e.clientX - disX;
        if (
          left >= this.positionX_A &&
          left <= this.positionX_C &&
          left >= -10 &&
          left <= 425
        ) {
          this.positionX_B = left;
          odiv.style.left = left + "px";
        }
      };
      document.onmouseup = (e) => {
        document.onmousemove = null;
        document.onmouseup = null;
      };
    },
    moveC(e) {
      let odiv = e.target; //獲取目標(biāo)元素
      //算出鼠標(biāo)相對(duì)元素的位置
      let disX = e.clientX - odiv.offsetLeft;
      document.onmousemove = (e) => {
        let left = e.clientX - disX;
        if (left >= this.positionX_B && left >= -10 && left <= 425) {
          this.positionX_C = left;
          odiv.style.left = left + "px";
        }
      };
      document.onmouseup = (e) => {
        document.onmousemove = null;
        document.onmouseup = null;
      };
    },

Css對(duì)應(yīng)的樣式

.bg {
  position: relative;
  display: flex;
  width: 435px;
  height: 10px;
  margin-top: 10px;
  background-color: #53bf6d;
  .txt0 {
    position: absolute;
    left: 0;
    top: 15px;
  }
  .txt100 {
    position: absolute;
    top: 15px;
    right: 0;
  }
  i {
    position: absolute;
    display: inline-block;
    height: 10px;
  }
  .A {
    background: #ff5757;
    z-index: 3;
    .Aptxt {
      position: absolute;
      top: 15px;
      right: -5px;
    }
  }
  .btnA {
    position: absolute;
    top: -5px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    border: solid 2px #0065bc;
    z-index: 3;
    cursor: ew-resize;
  }
  .btnB {
    content: "";
    position: absolute;
    top: -5px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    border: solid 2px #0065bc;
    z-index: 4;
    cursor: ew-resize;
  }
  .btnC {
    content: "";
    position: absolute;
    top: -5px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    border: solid 2px #0065bc;
    z-index: 4;
    cursor: ew-resize;
  }
  .B {
    background: #ffec58;
    z-index: 2 !important;
    .Bptxt {
      position: absolute;
      top: 15px;
      right: -5px;
    }
  }
  .C {
    background: #ffba00;
    z-index: 1 !important;
    .Cptxt {
      position: absolute;
      top: 15px;
      right: -5px;
    }
  }
}

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue項(xiàng)目打包部署流程分析

    vue項(xiàng)目打包部署流程分析

    這篇文章主要介紹了vue項(xiàng)目打包部署流程,本文通過實(shí)例圖文相結(jié)合給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-09-09
  • vue3自己封裝面包屑功能組件的幾種方式

    vue3自己封裝面包屑功能組件的幾種方式

    網(wǎng)站中我們經(jīng)常看到有個(gè)導(dǎo)航路徑,可以直觀地顯示當(dāng)前頁面的路徑,并快速返回之前的任意頁面,這是一個(gè)非常實(shí)用的功能,也是在Web前端必備的導(dǎo)航UI之一,這篇文章主要給大家介紹了關(guān)于vue3自己封裝面包屑功能組件的幾種方式,需要的朋友可以參考下
    2021-09-09
  • 解決Vue中mounted鉤子函數(shù)獲取節(jié)點(diǎn)高度出錯(cuò)問題

    解決Vue中mounted鉤子函數(shù)獲取節(jié)點(diǎn)高度出錯(cuò)問題

    本篇文章給大家分享了如何解決Vue中mounted鉤子函數(shù)獲取節(jié)點(diǎn)高度出錯(cuò)問題,對(duì)此有興趣的朋友可以參考學(xué)習(xí)下。
    2018-05-05
  • Vue.js項(xiàng)目中vue.config.js常用配置項(xiàng)介紹

    Vue.js項(xiàng)目中vue.config.js常用配置項(xiàng)介紹

    在VueCLI項(xiàng)目中,vue.config.js用于自定義構(gòu)建、開發(fā)和部署流程,本文詳細(xì)解析了其常用配置項(xiàng),包括基礎(chǔ)路徑、開發(fā)服務(wù)器、Webpack配置、CSS預(yù)處理、插件選項(xiàng)及環(huán)境變量管理等,并,通過代碼示例幫助開發(fā)者高效管理項(xiàng)目配置,提升開發(fā)體驗(yàn)
    2026-05-05
  • vue+swiper實(shí)現(xiàn)時(shí)間軸效果

    vue+swiper實(shí)現(xiàn)時(shí)間軸效果

    這篇文章主要為大家詳細(xì)介紹了vue+swiper實(shí)現(xiàn)時(shí)間軸效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • Vue綁定class和綁定內(nèi)聯(lián)樣式的實(shí)現(xiàn)方法

    Vue綁定class和綁定內(nèi)聯(lián)樣式的實(shí)現(xiàn)方法

    本文主要介紹了Vue綁定class和綁定內(nèi)聯(lián)樣式的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • 一文帶你搞懂Vue?Loader是如何工作的

    一文帶你搞懂Vue?Loader是如何工作的

    Vue?Loader?作為一個(gè)?webpack?的?Loader,扮演著將?.vue?文件轉(zhuǎn)化為瀏覽器可執(zhí)行代碼的角色,下面就跟隨小編一起深入了解Vue?Loader?的技術(shù)細(xì)節(jié)與工作機(jī)制吧
    2024-12-12
  • vue 根據(jù)選擇的月份動(dòng)態(tài)展示日期對(duì)應(yīng)的星期幾

    vue 根據(jù)選擇的月份動(dòng)態(tài)展示日期對(duì)應(yīng)的星期幾

    這篇文章主要介紹了vue 如何根據(jù)選擇的月份動(dòng)態(tài)展示日期對(duì)應(yīng)的星期幾,幫助大家更好的利用vue框架處理日期需求,感興趣的朋友可以了解下
    2021-02-02
  • vue點(diǎn)擊頁面空白處實(shí)現(xiàn)保存功能

    vue點(diǎn)擊頁面空白處實(shí)現(xiàn)保存功能

    這篇文章主要介紹了vue點(diǎn)擊頁面空白處實(shí)現(xiàn)保存功能,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-11-11
  • 關(guān)于vue中 $emit的用法詳解

    關(guān)于vue中 $emit的用法詳解

    這篇文章主要介紹了vue中 $emit的用法,通過實(shí)例代碼給大家介紹了子組件和父組件的相關(guān)知識(shí),需要的朋友參考下吧
    2018-04-04

最新評(píng)論

闸北区| 昂仁县| 承德县| 韶关市| 拉萨市| 南陵县| 兴安县| 全州县| 蒙阴县| 青岛市| 宝丰县| 涟水县| 彩票| 怀来县| 曲周县| 河东区| 尖扎县| 东丽区| 铜川市| 达孜县| 贵溪市| 石家庄市| 武邑县| 柘城县| 闻喜县| 济南市| 古交市| 南漳县| 临洮县| 大洼县| 虞城县| 泸州市| 突泉县| 宁海县| 东莞市| 拜城县| 怀柔区| 海丰县| 灯塔市| 和林格尔县| 明溪县|