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

vue實(shí)現(xiàn)移動(dòng)端原生小球滑塊

 更新時(shí)間:2022年03月08日 09:12:56   作者:至_臻  
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)移動(dòng)端原生小球滑塊,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue實(shí)現(xiàn)移動(dòng)端原生小球滑塊的具體代碼,供大家參考,具體內(nèi)容如下

效果

用到的一些事件

阻止默認(rèn)事件:ev.preventDefault && ev.preventDefault();

獲取寬度:getBoundingClientRect().width

點(diǎn)擊位置在元素的位置:ev.changedTouches[0].pageX

<template>
? <div id="app">
? ? <div class="slider">
? ? ? <div class="line"></div>
? ? ? <div class="line ac"></div>
? ? ? <div class="box" @touchstart="fnStart"></div>
? ? ? <div class="box as" @touchstart="fnStart"></div>
? ? </div>
? </div>
</template>

js

<script>
export default {
? methods: {
? ? fnStart(ev) {
? ? ? // 計(jì)算點(diǎn)擊位置在元素的坐標(biāo)
? ? ? this.disX = ev.changedTouches[0].pageX - ev.target.offsetLeft;
? ? ? // 獲取父節(jié)點(diǎn)
? ? ? this.parent = ev.target.parentNode;
? ? ? // 獲取元素的寬
? ? ? this.ow = this.parent.getBoundingClientRect().width;
? ? ? // 計(jì)算除了元素的寬盒子還剩下多寬
? ? ? this.clienw = this.ow - ev.target.getBoundingClientRect().width;
?
? ? ? // 獲取左邊小圓球
? ? ? this.lcircle = this.parent.children[2];
? ? ? // 獲取右邊小圓球
? ? ? this.rcircle = this.parent.children[3];
?
? ? ? // 獲取變色條
? ? ? this.line = this.parent.children[1];
?
? ? ? document.ontouchmove = this.fnmove;
? ? ? document.ontouchend = this.fnend;
? ? },
? ? fnmove(ev) {
? ? ? // 計(jì)算移動(dòng)的距離
? ? ? this.ll = ev.changedTouches[0].pageX - this.disX;
? ? ? // 判斷不能讓小圓球到盒子外面
? ? ? if (this.ll < 0) this.ll = 0;
? ? ? if (this.ll > this.clienw) this.ll = this.clienw;
? ? ? // 右邊線條
? ? ? if (ev.target.className.indexOf("as") != -1) {
? ? ? ? this.line.style.width =this.ll - this.parent.children[2].offsetLeft + "px";
? ? ? ? // 右邊推動(dòng)左邊小圓球
? ? ? ? // 判斷如果右邊小球移動(dòng)到左邊小于左邊小球offsetLeft的距離 如果當(dāng)前為0 加一個(gè)小圓球的寬他們就不會重疊
? ? ? ? console.log(this.ll)
? ? ? ? if (this.ll < this.lcircle.offsetLeft + 30) {
? ? ? ? ? // 如果this.ll大于左邊小球的值 當(dāng)前this.ll-30就是左邊小球left的值
? ? ? ? ? this.ind = this.ll - 30;
? ? ? ? ??
? ? ? ? ? console.log(this.ind)
? ? ? ? ? // 判斷當(dāng)前左邊位置過等于0 就讓他左邊的位置等于0 就不會到盒子外面
? ? ? ? ? if (this.ind <= 0) {
? ? ? ? ? ? this.ind = 0;
? ? ? ? ? }
? ? ? ? ? // 如果this.ll的值小于小圓球的寬 兩個(gè)圓就會重疊 ?所以讓右邊圓的left值為30
? ? ? ? ? if (this.ll < 30) {
? ? ? ? ? ? this.ll = 30;
? ? ? ? ? }
?
? ? ? ? ? this.line.style.left = this.ind + "px";
? ? ? ? ? this.lcircle.style.left = this.ind + "px";
? ? ? ? }
? ? ? } else {
? ? ? ? // 左線條
? ? ? ? // 獲取左邊的距離
? ? ? ? this.line.style.left = this.ll + "px";
? ? ? ? // 當(dāng)前this.ll就是line多出來的寬 ? 如果左邊不動(dòng) offsetleft的值是300 ? this.ll是移動(dòng)的距離
? ? ? ? this.line.style.width =
? ? ? ? ? this.parent.children[3].offsetLeft - this.ll + "px";
? ? ? ? // 左邊推動(dòng)右邊小圓球 ?要把右邊小球+30 不然兩個(gè)小球就會重合到一起
? ? ? ? if (this.ll + 30 > this.rcircle.offsetLeft) {
? ? ? ? ? this.indX = this.ll + 30;
?
? ? ? ? ? if (this.indX > this.clienw) {
? ? ? ? ? ? this.indX = this.clienw;
? ? ? ? ? }
?
? ? ? ? ? ? ? // 判斷當(dāng)前移動(dòng)的距離不能超過 this.clienw-30如果超過就會重疊
? ? ? ? ? if(this.ll>this.clienw-30){
? ? ? ? ? ? this.ll=this.clienw-30
? ? ? ? ? }
?
? ? ? ? ? this.line.style.left=this.indX+'px'
? ? ? ? ? this.rcircle.style.left=this.indX+'px'
? ? ? ? }
? ? ? }
?
? ? ? ev.target.style.left = this.ll + "px";
? ? },
? ? fnend() {
? ? ? document.ontouchmove = null;
? ? ? document.ontouchend = null;
? ? },
? },
};
</script>

css樣式 

<style scoped lang="less">
.slider {
? height: 30px;
? width: 300px;
? background: #999;
? position: relative;
? margin: auto;
? .box {
? ? width: 30px;
? ? height: 30px;
? ? border-radius: 50%;
? ? background: pink;
? ? position: absolute;
? }
? .box.as {
? ? background: blueviolet;
? ? right: 0;
? }
? // 線條
? .line {
? ? width: 300px;
? ? height: 5px;
? ? background: #eee;
? ? position: absolute;
? }
? .line.ac {
? ? background: rgb(247, 151, 25);
? }
}
</style>

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue實(shí)現(xiàn)從外部修改組件內(nèi)部的變量的值

    vue實(shí)現(xiàn)從外部修改組件內(nèi)部的變量的值

    這篇文章主要介紹了vue實(shí)現(xiàn)從外部修改組件內(nèi)部的變量的值,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • vue 判斷兩個(gè)時(shí)間插件結(jié)束時(shí)間必選大于開始時(shí)間的代碼

    vue 判斷兩個(gè)時(shí)間插件結(jié)束時(shí)間必選大于開始時(shí)間的代碼

    這篇文章主要介紹了vue 判斷兩個(gè)時(shí)間插件結(jié)束時(shí)間必選大于開始時(shí)間的代碼,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • Vue組件高級通訊之$children與$parent

    Vue組件高級通訊之$children與$parent

    這篇文章主要為大家介紹了Vue組件高級通訊之$children與$parent,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-06-06
  • vue中el-checkbox、el-switch綁定值問題詳解

    vue中el-checkbox、el-switch綁定值問題詳解

    這篇文章主要給大家介紹了關(guān)于vue中el-checkbox、el-switch綁定值問題的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用vue具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2024-01-01
  • vue.js 添加 fastclick的支持方法

    vue.js 添加 fastclick的支持方法

    今天小編就為大家分享一篇vue.js 添加 fastclick的支持方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • vue/Element?UI實(shí)現(xiàn)Element?UI?el-dialog自由拖動(dòng)功能實(shí)現(xiàn)

    vue/Element?UI實(shí)現(xiàn)Element?UI?el-dialog自由拖動(dòng)功能實(shí)現(xiàn)

    最近工作上需要在el-dialog基礎(chǔ)上進(jìn)行些功能的改動(dòng),下面這篇文章主要給大家介紹了關(guān)于vue/Element?UI實(shí)現(xiàn)Element?UI?el-dialog自由拖動(dòng)功能實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下
    2023-06-06
  • Vuex的actions屬性的具體使用

    Vuex的actions屬性的具體使用

    這篇文章主要介紹了Vuex的actions屬性的具體使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • Vue項(xiàng)目中封裝axios的方法

    Vue項(xiàng)目中封裝axios的方法

    這篇文章主要介紹了Vue項(xiàng)目中封裝axios的方法,axios 是一個(gè)輕量的 HTTP客戶端,基于 XMLHttpRequest 服務(wù)來執(zhí)行 HTTP 請求,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-05-05
  • vue 組件高級用法實(shí)例詳解

    vue 組件高級用法實(shí)例詳解

    這篇文章主要介紹了vue 組件高級用法,需要的朋友可以參考下
    2018-04-04
  • vue解決花括號數(shù)據(jù)綁定不成功的問題

    vue解決花括號數(shù)據(jù)綁定不成功的問題

    今天小編就為大家分享一篇vue解決花括號數(shù)據(jù)綁定不成功的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-10-10

最新評論

禹州市| 武汉市| 信阳市| 柳河县| 石棉县| 繁峙县| 莱芜市| 安康市| 阿勒泰市| 曲阳县| 锦州市| 司法| 保山市| 双流县| 莲花县| 泰安市| 曲阳县| 鄂州市| 江城| 桃源县| 扎兰屯市| 克拉玛依市| 兰西县| 阿勒泰市| 治县。| 财经| 韶山市| 夏河县| 葫芦岛市| 托克逊县| 天台县| 湘潭市| 南雄市| 夹江县| 阳曲县| 安庆市| 北碚区| 东光县| 栾城县| 密云县| 行唐县|