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

vue實現(xiàn)滑動解鎖功能

 更新時間:2022年03月03日 12:06:22   作者:Archer_yy  
這篇文章主要為大家詳細介紹了vue實現(xiàn)滑動解鎖功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了vue實現(xiàn)滑動解鎖功能的具體代碼,供大家參考,具體內(nèi)容如下

話不多說,直接上代碼;

<template>
? <div>
? ? <div id="box">
? ? ? <div class="bgColor"></div>
? ? ? <div class="txt">滑動解鎖</div>
? ? ? <!--給i標簽添加上相應字體圖標的類名即可-->
? ? ? <div class="slider">
? ? ? ? <i v-show="!isSuccess" class="el-icon-d-arrow-right"></i>
? ? ? ? <i v-show="isSuccess" class="el-icon-check"></i>
? ? ? </div>
? ? </div>
? </div>
</template>

<script>
export default {
? mounted() {
? ? var self = this;
? ? //一、定義了一個獲取元素的方法
? ? function getEle(selector) {
? ? ? return document.querySelector(selector);
? ? }
? ? //二、獲取到需要用到的DOM元素
? ? var box = getEle("#box"), //容器
? ? ? bgColor = getEle(".bgColor"), //背景色
? ? ? txt = getEle(".txt"), //文本
? ? ? slider = getEle(".slider"), //滑塊
? ? ? icon = getEle(".slider>i"),
? ? ? successMoveDistance = box.offsetWidth - slider.offsetWidth, //解鎖需要滑動的距離
? ? ? downX; //用于存放鼠標按下時的位置
? ? //三、給滑塊添加鼠標按下事件
? ? slider.onmousedown = mousedownHandler;
? ? slider.ontouchstart = mousedownHandler; //移動端加touchstart事件
? ? //3.1鼠標按下事件的方法實現(xiàn)
? ? function mousedownHandler(e) {
? ? ? bgColor.style.transition = "";
? ? ? slider.style.transition = "";
? ? ? var e = e || window.event || e.which;
? ? ? downX = e.clientX ? e.clientX : e.changedTouches[0].clientX;
? ? ? if (!self.isSuccess) {
? ? ? ? //在鼠標按下時,分別給鼠標添加移動和松開事件
? ? ? ? document.onmousemove = mousemoveHandler;
? ? ? ? document.onmouseup = mouseupHandler;
? ? ? ? //添加移動端對應事件
? ? ? ? document.ontouchmove = mousemoveHandler;
? ? ? ? document.ontouchend = mouseupHandler;
? ? ? }
? ? }
? ? //四、定義一個獲取鼠標當前需要移動多少距離的方法
? ? function getOffsetX(offset, min, max) {
? ? ? if (offset < min) {
? ? ? ? offset = min;
? ? ? } else if (offset > max) {
? ? ? ? offset = max;
? ? ? }
? ? ? return offset;
? ? }
? ? //3.1.1鼠標移動事件的方法實現(xiàn)
? ? function mousemoveHandler(e) {
? ? ? var e = e || window.event || e.which;
? ? ? var moveX = e.clientX ? e.clientX : e.changedTouches[0].clientX;
? ? ? console.log(moveX);
? ? ? var offsetX = getOffsetX(moveX - downX, 0, successMoveDistance);
? ? ? bgColor.style.width = offsetX + "px";
? ? ? slider.style.left = offsetX + "px";

? ? ? if (offsetX == successMoveDistance) {
? ? ? ? success();
? ? ? }
? ? ? //如果不設置滑塊滑動時會出現(xiàn)問題(目前還不知道為什么)
? ? ? e.preventDefault();
? ? }
? ? //3.1.2鼠標松開事件的方法實現(xiàn)
? ? function mouseupHandler(e) {
? ? ? if (!self.isSuccess) {
? ? ? ? bgColor.style.width = 0 + "px";
? ? ? ? slider.style.left = 0 + "px";
? ? ? ? bgColor.style.transition = "width 0.5s linear";
? ? ? ? slider.style.transition = "left 0.5s linear";
? ? ? }
? ? ? document.onmousemove = null;
? ? ? document.onmouseup = null;
? ? ? //移除移動端事件
? ? ? document.ontouchmove = null;
? ? ? document.ontouchend = null;
? ? }
? ? //五、定義一個滑塊解鎖成功的方法
? ? function success() {
? ? ? self.isSuccess = true;
? ? ? txt.innerHTML = "解鎖成功";
? ? ? bgColor.style.backgroundColor = "lightgreen";
? ? ? //滑動成功時,移除鼠標按下事件和鼠標移動事件
? ? ? slider.onmousedown = null;
? ? ? document.onmousemove = null;
? ? ? //移除移動端事件
? ? ? document.ontouchstart = null;
? ? ? document.ontouchmove = null;
? ? }
? },
? data() {
? ? return {
? ? ? isSuccess: false,
? ? };
? },
};
</script>
<style>
/* ?使用全局樣式樣式去掉 */
* { touch-action: pan-y; }?
</style>
<style>
#box {
? position: relative;
? width: 300px;
? height: 40px;
? margin: 0 auto;
? margin-top: 10px;
? background-color: #e8e8e8;
? box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
}
.bgColor {
? position: absolute;
? left: 0;
? top: 0;
? width: 40px;
? height: 40px;
? background-color: lightblue;
}
.txt {
? position: absolute;
? width: 100%;
? height: 40px;
? line-height: 40px;
? font-size: 14px;
? color: #000;
? text-align: center;
}
.slider {
? position: absolute;
? left: 0;
? top: 0;
? width: 50px;
? height: 40px;
? /* border: 1px solid #ccc; */
? background: #fff;
? text-align: center;
? cursor: move;
}
.slider > i {
? position: absolute;
? top: 50%;
? left: 50%;
? transform: translate(-50%, -50%);
}
</style>

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

相關文章

  • 詳解Vue前端生產(chǎn)環(huán)境發(fā)布配置實戰(zhàn)篇

    詳解Vue前端生產(chǎn)環(huán)境發(fā)布配置實戰(zhàn)篇

    這篇文章主要介紹了詳解Vue前端生產(chǎn)環(huán)境發(fā)布配置實戰(zhàn)篇,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-05-05
  • 解決elementUI 切換tab后 el_table 固定列下方多了一條線問題

    解決elementUI 切換tab后 el_table 固定列下方多了一條線問題

    這篇文章主要介紹了解決elementUI 切換tab后 el_table 固定列下方多了一條線問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • vue3 中使用 reactive 的問題小結

    vue3 中使用 reactive 的問題小結

    在 Vue 3 中,如果你使用 reactive 來定義一個響應式對象,那么這個對象的屬性是不能被重新賦值的,因為 reactive 會將對象的屬性轉換為 getter/setter,這樣 Vue 才能追蹤到屬性的變化,這篇文章主要介紹了vue3 中使用 reactive 的問題,需要的朋友可以參考下
    2024-03-03
  • 記錄--使用el-time-picker默認值遇到的問題

    記錄--使用el-time-picker默認值遇到的問題

    這篇文章主要介紹了記錄--使用el-time-picker默認值遇到的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • 使用Vite搭建vue3+TS項目的實現(xiàn)步驟

    使用Vite搭建vue3+TS項目的實現(xiàn)步驟

    本文主要介紹了使用Vite搭建vue3+TS項目的實現(xiàn)步驟,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-01-01
  • Vue使用Tinymce富文本自定義toolbar按鈕的實踐

    Vue使用Tinymce富文本自定義toolbar按鈕的實踐

    本文主要介紹了Vue使用Tinymce富文本自定義toolbar按鈕,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • 使用Vue.js實現(xiàn)一個循環(huán)倒計時功能

    使用Vue.js實現(xiàn)一個循環(huán)倒計時功能

    在Web應用中,倒計時功能常用于各種場景,如活動倒計時、定時任務提醒等,Vue.js作為一款輕量級的前端框架,提供了豐富的工具和API來實現(xiàn)這些功能,本文將詳細介紹如何使用Vue.js實現(xiàn)一個循環(huán)倒計時功能,需要的朋友可以參考下
    2024-09-09
  • Vue取消Axios發(fā)出的請求

    Vue取消Axios發(fā)出的請求

    axios 是一個基于 promise 的 HTTP 庫,可以用在瀏覽器和 node.js 中。首先需要知道:axios不是一種新的技術。axios 是一個基于Promise 用于瀏覽器和 nodejs 的 HTTP 客戶端,本質(zhì)上也是對原生XHR的封裝,只不過它是Promise的實現(xiàn)版本,符合最新的ES規(guī)范
    2022-09-09
  • vue-router后臺鑒權流程實現(xiàn)

    vue-router后臺鑒權流程實現(xiàn)

    本文主要介紹了vue-router后臺鑒權流程實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-08-08
  • 使用Vuex實現(xiàn)一個筆記應用的方法

    使用Vuex實現(xiàn)一個筆記應用的方法

    這篇文章主要介紹了使用Vuex實現(xiàn)一個筆記應用的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03

最新評論

嘉鱼县| 忻城县| 汉源县| 上高县| 二手房| 长沙市| 东至县| 灵台县| 尤溪县| 浠水县| 茂名市| 遂宁市| 图木舒克市| 河池市| 平潭县| 威海市| 陆丰市| 刚察县| 泰来县| 海城市| 太保市| 莲花县| 白山市| 嫩江县| 清徐县| 芷江| 巴青县| 株洲县| 诸城市| 辽阳县| 阜平县| 沈阳市| 河津市| 开江县| 上杭县| 大连市| 昌都县| 邵东县| 焦作市| 汽车| 肇庆市|