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

vue實(shí)現(xiàn)移動(dòng)滑塊驗(yàn)證

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

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

記錄一下今天的學(xué)習(xí)內(nèi)容

<div class="solidBox" :class="{'solidBox1': validation}">
? ? <div @mousedown="solidStar" class="solid" :class="{'solid1': validation}"></div>
? ? {{!validation? textStart : textEnd}}
</div>
.solidBox {
? ? ? ? ? position: relative;
? ? ? ? ? display: flex;
? ? ? ? ? justify-content: center;
? ? ? ? ? align-items: center;
? ? ? ? ? margin: 20px 0;
? ? ? ? ? width: 100%;
? ? ? ? ? height: 35px;
? ? ? ? ? background-color: #999999;
? ? ? ? ? .solid {
? ? ? ? ? ? position: absolute;
? ? ? ? ? ? left: 0;
? ? ? ? ? ? display: flex;
? ? ? ? ? ? justify-content: center;
? ? ? ? ? ? align-items: center;
? ? ? ? ? ? width: 35px;
? ? ? ? ? ? height: 35px;
? ? ? ? ? ? cursor: pointer;
? ? ? ? ? ? border: 1px solid #666666;
? ? ? ? ? ? background: url("/img/切圖2/arrow2.png") center no-repeat;
? ? ? ? ? ? background-color: #ffffff;
? ? ? ? ? ? box-sizing: border-box;
? ? ? ? ? }
? ? ? ? ? .solid1 {
? ? ? ? ? ? background: url("/img/切圖2/ok.png") center no-repeat;
? ? ? ? ? ? background-size: 100%;
? ? ? ? ? ? border: 1px solid #358097;
? ? ? ? ? }
? ? ? ? }
? ? ? ? .solidBox1 {
? ? ? ? ? color: #ffffff;
? ? ? ? ? background-color: #1aad19;
? ? ? ? }

方法寫(xiě)在methods里面

//鼠標(biāo)按下時(shí)
solidStar(e) {
? ? ? // console.log(e);
? ? ? // 獲取當(dāng)前DOM元素寬度 鼠標(biāo)當(dāng)前點(diǎn)擊位置
? ? ? let solidDom = e.target;
? ? ? let moveStart = e.clientX;
? ? ? let solidDomWith = solidDom.offsetWidth;
? ? ? // 父節(jié)點(diǎn)減去滑塊寬度獲取滑塊最大移動(dòng)距離
? ? ? let MaxW = e.path[1].clientWidth - solidDomWith;
? ? ? // 設(shè)置判斷條件 防止驗(yàn)證成功后鼠標(biāo)移動(dòng)方法繼續(xù)被調(diào)用
? ? ? if (this.validation === true) {
? ? ? ? return false;
? ? ? }
? ? ? // 鼠標(biāo)移動(dòng)
? ? ? (document.onmousemove = e => {
? ? ? ? // 獲取移動(dòng)時(shí)鼠標(biāo)距離瀏覽器左上角到當(dāng)前位置的X軸距離
? ? ? ? let endX = e.clientX;
? ? ? ? // 從上面獲取到的數(shù)據(jù)計(jì)算出鼠標(biāo)移動(dòng)的距離
? ? ? ? this.moveX = endX - moveStart;
? ? ? ? // 判斷如果用戶(hù)反方向移動(dòng)將移動(dòng)距離賦值為零
? ? ? ? if (this.moveX <= 0) {
? ? ? ? ? this.moveX = 0;
? ? ? ? }
? ? ? ? // 判斷如果滑塊移動(dòng)距離大于最大寬度 ?給其賦值最大寬度
? ? ? ? if (this.moveX >= MaxW) {
? ? ? ? ? this.moveX = MaxW;
? ? ? ? }
? ? ? ? // 為了更好地體驗(yàn) 寫(xiě)上動(dòng)畫(huà) 要不都不寫(xiě) ?不然其他動(dòng)畫(huà)會(huì)覆蓋向右拖拽動(dòng)作
? ? ? ? solidDom.style.transition = "0s all";
? ? ? ? solidDom.style.left = this.moveX + "px";
? ? ? ? // 很關(guān)鍵的地方 e.preventDefault()這個(gè)方法會(huì)關(guān)閉與當(dāng)前事件關(guān)聯(lián)的其他動(dòng)作 只執(zhí)行此事件
? ? ? ? e.preventDefault();
? ? ? }),
? ? ? ? // 鼠標(biāo)抬起
? ? ? ? (document.onmouseup = () => {
? ? ? ? ? // 如果鼠標(biāo)抬起后拖拽距離沒(méi)到可移動(dòng)距離最大值將返回起點(diǎn)0
? ? ? ? ? if (this.moveX !== MaxW) {
? ? ? ? ? ? solidDom.style.transition = ".5s linear";
? ? ? ? ? ? solidDom.style.left = 0;
? ? ? ? ? } else {
? ? ? ? ? ? // 如果成功設(shè)置判斷條件
? ? ? ? ? ? this.validation = true;
? ? ? ? ? }
? ? ? ? ? // 動(dòng)作完成后將事件清空
? ? ? ? ? document.onmousemove = null;
? ? ? ? ? document.onmouseup = null;
? ? ? ? });
? ? }
export default {
? name: "twologin",
? data() {
? ? return {
? ? ? loginBoxShow: true,
? ? ? isActive: 0,
? ? ? userName: "",
? ? ? psd: "",
? ? ? input1: "",
? ? ? input2: "",
? ? ? select: "",
? ? ? validation: false,
? ? ? textStart: "向右拖動(dòng)滑塊",
? ? ? textEnd: "驗(yàn)證成功",
? ? ? moveX: 0
? ? };
? },

最后寫(xiě)一點(diǎn)今天學(xué)到的知識(shí)點(diǎn)

  • event.screenX是屏幕左上角到鼠標(biāo)當(dāng)前位置的x軸距離
  • event.clientX是瀏覽器左上角到鼠標(biāo)當(dāng)前位置的x軸距離
  • event.offsetX是鼠標(biāo)當(dāng)前點(diǎn)擊控件左上角到鼠標(biāo)當(dāng)前位置的x軸距離
  • evevt.preventDefault()

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

相關(guān)文章

  • 深入淺析Vue中的 computed 和 watch

    深入淺析Vue中的 computed 和 watch

    computed 計(jì)算屬性是通過(guò)屬性計(jì)算得來(lái)的屬性,watch屬性變化,就會(huì)觸發(fā)監(jiān)聽(tīng)的函數(shù)。下面通過(guò)本文給大家介紹Vue中的 computed 和 watch,感興趣的朋友一起看看吧
    2018-06-06
  • vscode 配置vue+vetur+eslint+prettier自動(dòng)格式化功能

    vscode 配置vue+vetur+eslint+prettier自動(dòng)格式化功能

    這篇文章主要介紹了vscode 配置vue+vetur+eslint+prettier自動(dòng)格式化功能,本文通過(guò)實(shí)例代碼圖文的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-03-03
  • 跟混亂的頁(yè)面彈窗說(shuō)再見(jiàn)

    跟混亂的頁(yè)面彈窗說(shuō)再見(jiàn)

    這篇文章主要介紹了跟混亂的頁(yè)面彈窗說(shuō)再見(jiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • Vue.extend和VueComponent的關(guān)系源碼解析

    Vue.extend和VueComponent的關(guān)系源碼解析

    這篇文章主要為大家詳解了Vue.extend和VueComponent的關(guān)系源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-02-02
  • 解決vue-router 嵌套路由沒(méi)反應(yīng)的問(wèn)題

    解決vue-router 嵌套路由沒(méi)反應(yīng)的問(wèn)題

    這篇文章主要介紹了解決vue-router 嵌套路由沒(méi)反應(yīng)的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-09-09
  • Vue詳細(xì)的入門(mén)筆記

    Vue詳細(xì)的入門(mén)筆記

    這篇文章主要介紹了Vue詳細(xì)的入門(mén)筆記,對(duì)Vue感興趣的同學(xué),可以參考下
    2021-05-05
  • tomcat部署前端vue項(xiàng)目步驟(項(xiàng)目上線(xiàn)具體操作)

    tomcat部署前端vue項(xiàng)目步驟(項(xiàng)目上線(xiàn)具體操作)

    在實(shí)際開(kāi)發(fā)中,我們經(jīng)常會(huì)遇到將Vue項(xiàng)目部署到Tomcat服務(wù)器上的需求,下面這篇文章主要給大家介紹了關(guān)于tomcat部署前端vue項(xiàng)目(項(xiàng)目上線(xiàn)具體操作)的相關(guān)資料,需要的朋友可以參考下
    2024-07-07
  • vue中this.$http.post()跨域和請(qǐng)求參數(shù)丟失的解決

    vue中this.$http.post()跨域和請(qǐng)求參數(shù)丟失的解決

    這篇文章主要介紹了vue中this.$http.post()跨域和請(qǐng)求參數(shù)丟失的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • vue中eslintrc.js配置最詳細(xì)介紹

    vue中eslintrc.js配置最詳細(xì)介紹

    這篇文章主要介紹了vue中eslintrc.js配置最詳細(xì)介紹,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-12-12
  • 關(guān)于vue3中的reactive賦值問(wèn)題

    關(guān)于vue3中的reactive賦值問(wèn)題

    這篇文章主要介紹了關(guān)于vue3中的reactive賦值問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05

最新評(píng)論

永城市| 车险| 军事| 临西县| 南溪县| 松原市| 三门县| 安宁市| 兴义市| 黄梅县| 临湘市| 三门县| 股票| 池州市| 正宁县| 高陵县| 嘉定区| 乌审旗| 洪江市| 蚌埠市| 都兰县| 洪洞县| 达孜县| 白山市| 上饶市| 左贡县| 赞皇县| 九江县| 甘洛县| 三穗县| 安多县| 赣州市| 新平| 清涧县| 无棣县| 万州区| 济源市| 理塘县| 太仆寺旗| 黔西县| 潞西市|