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

vue項(xiàng)目實(shí)現(xiàn)自定義滑塊過(guò)渡效果

 更新時(shí)間:2024年07月27日 09:38:48   作者:小影_8978  
這篇文章主要介紹了vue項(xiàng)目實(shí)現(xiàn)自定義滑塊過(guò)渡效果,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

vue自定義滑塊過(guò)渡效果

  • html部分:
<div class="slider-main">
    <div class="slider">
      <span v-show="value !== ''" class="pointer" :style="`background-color: ${pointerColor}; left: ${pointerLeft}%`" />
    </div>
    <div class="data-text">
      <span class="min-max">{{ max }}%</span>
      <span class="min-max">{{ min }}%</span>
    </div>
  </div>
  • css代碼:
 .slider-main {
    width: 100%;
    .slider {
      flex: 1;
      height: 14px;
      border-radius: 20px;
      background: linear-gradient(to right,  #F59292, #95D8A4);
      position: relative;
      rotate: 180deg;
      .pointer {
        position: absolute;
        width: 24px;
        height: 35px;
        top: 50%;
        transform: translate(-50%, -50%);
        
        border-radius: 24px;
        border: 3px solid #fff;
        left: 50%;
      }
    }
    .data-text {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .min-max {
        font-size: 12px;
        color: #666;
        margin: 0 5px;
      }
    }
    
  }
  • js部分:
export default {
  props: {
    value: {
      type: [Number, String],
      default: ''
    },
    min: {
      type: Number,
      default: -100
    },
    max: {
      type: Number,
      default: 100
    },
  },
  computed: {
    pointerColor () {
      // 獲取當(dāng)前值對(duì)應(yīng)的顏色
      // return this.colorToHex(currentColor);
      return tools.valueToColor(this.min, this.max, this.value);
    },
    pointerLeft () {
      return this.calculateLeftPosition(this.value, this.min, this.max)
    }
  },
  methods: {
    // 計(jì)算當(dāng)前的left的位置
    calculateLeftPosition(actualValue, minValue, maxValue) {
      // 確保實(shí)際值不小于最小值,不大于最大值
      actualValue = Math.max(minValue, Math.min(maxValue, actualValue));
      // 計(jì)算left值
      var left = (actualValue - minValue) / (maxValue - minValue) * 100;
      // 返回left值
      return left;
    },
  }
}

vue寫滑塊組件

<template>
  <div @touchend="down = false" @touchmove="gotouchstart" class="pledge">
    <!-- <div class="mask" @touchend="down = false" @touchmove="gotouchstart"></div> -->
    <div class="h2">調(diào)整質(zhì)押率</div>
    <!-- 已借數(shù)量和質(zhì)押金額 -->
    <div class="info">
      <div>已借數(shù)量</div>
      <div>1,001.48292837 USDT</div>
    </div>
    <div class="info">
      <div>質(zhì)押金額</div>
      <div>1.48292837 BTC</div>
    </div>
    <!-- 滑塊背景 -->
    <div class="box">
      <div style="border-right: 1px solid #0f9d58">
        <div class="text">65%</div>
        <div class="text">初始質(zhì)押率</div>
        <div class="low col">低風(fēng)險(xiǎn)</div>
        <div class="round">
          <div></div>
        </div>
        <div class="round" style="bottom: -4px; left: -4px">
          <div></div>
        </div>
        <div class="round" style="top: -4px; right: -4px">
          <div style="background: #0f9d58"></div>
        </div>
      </div>
      <div style="border-right: 1px solid #d23f31">
        <div class="text">83%</div>
        <div class="text">平倉(cāng)質(zhì)押率</div>
        <div class="danger col">高風(fēng)險(xiǎn)</div>
        <div class="round">
          <div></div>
        </div>
        <div class="round" style="top: -4px; right: -4px">
          <div style="background: #d23f31"></div>
        </div>
      </div>
    </div>
    <!-- 滑塊 -->
    <div class="slider" ref="sliderRef">
      <div
        class="slider_box"
        :style="{ left: sliderLeft + 'px' }"
        @touchstart="down = true"
      >
        | | |
      </div>
      <div class="percent" :style="{ left: percentLeft + 'px' }">
        <div>LTV</div>
        <div style="color: #0f9d58; font-weight: bold">{{ percent }}%</div>
      </div>
    </div>
    <!-- 還款總額彈窗 -->
    <div class="title">質(zhì)押金額</div>
    <div class="input">
      <div class="type">增加</div>
      <input type="text" v-model="money" @keyup="formatInput" />
      <div class="unit">
        <span style="margin-right: 5px">MAX</span>
        <span style="color: rgba(0, 0, 0, 0.87)">USDT</span>
      </div>
    </div>
    <div class="btn">增加質(zhì)押金</div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      sliderLeft: -16, // 滑塊左側(cè)距離
      percentLeft: -21, // 百分比的側(cè)距離
      percent: 1, // 百分比
      down: false, // 控制滑塊
      money: 0,
    }
  },
 
  mounted() {},
 
  methods: {
    // 滑塊拖動(dòng)
    gotouchstart(e) {
      if (this.down) {
        let width = this.$refs.sliderRef.getBoundingClientRect().width
        // 計(jì)算距離
        let left =
          Math.round(e.targetTouches[0].clientX) -
          Math.round(this.$refs.sliderRef.getBoundingClientRect().left)
        if (left < 0) {
          this.sliderLeft = -17
          this.percentLeft = -27
        } else if (left > width) {
          this.sliderLeft = width - 17
          this.percentLeft = width - 27
        } else {
          this.sliderLeft = left - 17
          this.percentLeft = left - 27
        }
        // 計(jì)算百分比
        if (left > 0 && left < width / 2) {
          this.percent = Math.round((left / width) * 2 * 65)
          this.percent = this.percent ? this.percent : 1
        } else if (left > width / 2 && left < width) {
          this.percent = Math.round(((left - width / 2) / width) * 2 * 18 + 65)
        } else if (left < 0) {
          this.percent = 1
        } else if (left > width) {
          this.percent = 83
        }
      }
    },
    // 數(shù)字處理
    formatInput() {
      if (typeof this.money !== 'string') {
        this.money = this.money.toString()
      }
      // 先把非數(shù)字的都替換掉,除了數(shù)字和.
      this.money = this.money.replace(/[^\d.]/g, '')
      // 必須保證第一個(gè)為數(shù)字而不是.
      this.money = this.money.replace(/^\./g, '')
      // 保證只有出現(xiàn)一個(gè).而沒(méi)有多個(gè).
      this.money = this.money.replace(/\.{2,}/g, '')
      // 保證.只出現(xiàn)一次,而不能出現(xiàn)兩次以上
      this.money = this.money
        .replace('.', '$#$')
        .replace(/\./g, '')
        .replace('$#$', '.')
      // 只能輸入小數(shù)點(diǎn)后8位
      const reg = '^(-)*(\\d+)\\.(\\d{' + 8 + '}).*$'
      this.money = this.money.replace(new RegExp(reg), '$1$2.$3')
    },
  },
}
</script>
<style lang="less" scoped>
.pledge {
  padding: 16px;
  position: relative;
  overflow: hidden;
  .h2 {
    font-family: DIN Pro;
    font-style: normal;
    font-weight: bold;
    font-size: 16px;
    line-height: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 36px;
  }
  .mask {
    width: 100wh;
    height: 100vh;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: -1;
  }
}
.info {
  font-family: DIN Pro;
  font-size: 14px;
  font-style: normal;
  line-height: 18px;
  letter-spacing: 0em;
  text-align: left;
  display: flex;
  margin: 20px 0 30px 0;
}
.info :first-child {
  color: #86868b;
  min-width: 80px;
}
.info :last-child {
  color: #1d1d1f;
  font-weight: bold;
}
 
.title {
  font-family: DIN Pro;
  font-style: normal;
  font-weight: bold;
  font-size: 14px;
  line-height: 18px;
  color: #1d1d1f;
  margin: 8px 0;
}
.input {
  display: flex;
  height: 50px;
  justify-content: space-between;
  align-items: center;
  background: #f5f5f7;
  border-radius: 4px;
  padding: 0 15px;
  .type {
    width: 80px;
    height: 40px;
    margin-right: 5px;
    border-right: 1px solid #e6e6e9;
    font-family: DIN Pro;
    font-style: normal;
    font-weight: normal;
    font-size: 14px;
    line-height: 40px;
    color: rgba(0, 0, 0, 0.87);
  }
  input {
    width: 120px;
    background: none;
    outline: none;
    border: none;
    font-family: DIN Pro;
    font-style: normal;
    font-weight: normal;
    font-size: 16px;
    line-height: 26px;
    color: rgba(0, 0, 0, 0.87);
  }
  .unit {
    font-family: DIN Pro;
    font-size: 14px;
    font-style: normal;
    font-weight: 400;
    line-height: 18px;
    letter-spacing: 0em;
    color: #14c393;
  }
}
.btn {
  height: 40px;
  background: #14c393;
  border-radius: 10px;
  color: #ffffff;
  font-family: DIN Pro;
  font-style: normal;
  font-weight: bold;
  font-size: 14px;
  line-height: 18px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 25px;
  margin-top: 16px;
}
.slider {
  width: 100%;
  height: 100px;
  position: relative;
  .slider_box {
    display: flex;
    justify-content: center;
    align-items: center;
    color: #a1a1a6;
    width: 34px;
    height: 32px;
    background: #ffffff;
    border: 1px solid #e6e6e9;
    box-sizing: border-box;
    box-shadow: 0px 0px 3px rgba(101, 119, 134, 0.15),
      0px 0px 15px rgba(101, 119, 134, 0.2);
    border-radius: 8px;
    position: absolute;
    top: 0%;
    transform: translateY(-50%);
    z-index: 10;
  }
  .percent {
    position: absolute;
    top: 30px;
    width: 55px;
    height: 42px;
    background-color: #fff;
    box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.08),
      0px 4px 8px rgba(50, 50, 71, 0.006);
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    font-size: 12px;
    line-height: 16px;
    font-family: DIN Pro;
    font-style: normal;
    font-weight: normal;
    color: #515154;
  }
}
.box {
  display: flex;
  flex: 2;
  margin-top: 16px;
  > div {
    flex: 1;
    text-align: right;
    position: relative;
  }
  .text {
    font-family: DIN Pro;
    font-style: normal;
    font-weight: normal;
    font-size: 12px;
    line-height: 16px;
    color: #515154;
    margin-right: 4px;
  }
  .col {
    height: 50px;
    margin-top: 18px;
    font-family: DIN Pro;
    font-style: normal;
    font-weight: bold;
    font-size: 12px;
    line-height: 16px;
    padding-right: 4px;
    padding-top: 4px;
  }
  .round {
    width: 8px;
    height: 8px;
    background: #ffffff;
    border: 1px solid #e6e6e9;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    position: absolute;
    bottom: -4px;
    right: -4px;
    z-index: 5;
    > div {
      width: 4px;
      height: 4px;
      background: #1d1d1f;
      border-radius: 50%;
    }
  }
  .low {
    background: rgba(15, 157, 88, 0.2);
    color: #0f9d58;
    border-bottom: 2px solid #0f9d58;
  }
  .danger {
    background: rgba(210, 63, 49, 0.2);
    color: #d23f31;
    border-bottom: 2px solid #d23f31;
  }
}
</style>

總結(jié)

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

相關(guān)文章

  • Vue基礎(chǔ)教程之條件渲染和列表渲染

    Vue基礎(chǔ)教程之條件渲染和列表渲染

    Vue會(huì)盡可能高效地渲染元素,通常會(huì)復(fù)用已有元素而不是從頭開始渲染。這么做會(huì)使Vue變得非???下面這篇文章主要給大家介紹了Vue基礎(chǔ)教程之條件渲染和列表渲染的相關(guān)資料,需要的朋友可以參考下
    2021-11-11
  • springboot+vue實(shí)現(xiàn)文件上傳下載

    springboot+vue實(shí)現(xiàn)文件上傳下載

    這篇文章主要為大家詳細(xì)介紹了springboot+vue實(shí)現(xiàn)文件上傳下載,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-11-11
  • MVVM模型在Vue中的使用詳解

    MVVM模型在Vue中的使用詳解

    MVVM模型主要是為了分離視圖(View)和模型(Model),其優(yōu)點(diǎn)為:低耦合、可重用性、獨(dú)立開發(fā)以及可測(cè)試,視圖和模型分離的特點(diǎn)給了 Vue 很大的啟發(fā),這篇文章主要介紹了MVVM模型在Vue中的使用,需要的朋友可以參考下
    2022-11-11
  • nuxt 實(shí)現(xiàn)在其它js文件中使用store的方式

    nuxt 實(shí)現(xiàn)在其它js文件中使用store的方式

    這篇文章主要介紹了nuxt 實(shí)現(xiàn)在其它js文件中使用store的方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-11-11
  • 關(guān)于json-bigint處理大數(shù)字問(wèn)題

    關(guān)于json-bigint處理大數(shù)字問(wèn)題

    這篇文章主要介紹了關(guān)于json-bigint處理大數(shù)字問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • vue中實(shí)現(xiàn)打印功能的幾種方法示例

    vue中實(shí)現(xiàn)打印功能的幾種方法示例

    這篇文章主要給大家介紹了關(guān)于vue中實(shí)現(xiàn)打印功能的幾種方法,打印功能在實(shí)際開發(fā)中非常常見,通常我們需要將網(wǎng)頁(yè)中的某一部分或整個(gè)網(wǎng)頁(yè)打印出來(lái),需要的朋友可以參考下
    2023-09-09
  • vue3中展示markdown格式文章的三種形式

    vue3中展示markdown格式文章的三種形式

    這篇文章主要為大家詳細(xì)介紹了vue3中展示markdown格式文章的三種形式,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2025-04-04
  • vue3?封裝自定義組件v-model的示例

    vue3?封裝自定義組件v-model的示例

    這篇文章主要介紹了vue3?封裝自定義組件v-model及自定義組件使用v-model,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-07-07
  • element ui中表單el-form的label如何設(shè)置寬度

    element ui中表單el-form的label如何設(shè)置寬度

    這篇文章主要介紹了element ui中表單el-form的label如何設(shè)置寬度,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • vue中el-input綁定鍵盤按鍵(按鍵修飾符)

    vue中el-input綁定鍵盤按鍵(按鍵修飾符)

    這篇文章主要介紹了vue中el-input綁定鍵盤按鍵(按鍵修飾符),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-07-07

最新評(píng)論