亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Vue如何實現滑動驗證功能

發布時間:2022-02-17 09:12:20 來源:億速云 閱讀:689 作者:小新 欄目:開發技術

這篇文章主要介紹了Vue如何實現滑動驗證功能,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

用Vue實現滑動驗證碼,鼠標點擊滑動驗證,驗證成功之后會顯示驗證通過。

程序分析

1、鼠標的點擊
2、滑塊的拖動
3、未驗證之前滑動條上顯示的文字
4、滑塊箭頭指向Vue函數
5、判斷是否拖動完畢
6、拖動完畢時改變背景色并顯示驗證成功

效果圖演示

原始狀態

Vue如何實現滑動驗證功能

點擊之后拖動

Vue如何實現滑動驗證功能

拖動完畢

Vue如何實現滑動驗證功能

有沒有感覺很奇妙的呢???

在欣賞代碼之前準備工作要做好的!!!
**特別注意:**相關架包的引入(三個架包)

<script src="js/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="js/jquery.js"></script>

代碼演示

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="js/vue.js"></script>
        <script src="https://unpkg.com/element-ui/lib/index.js"></script>
        <script src="js/jquery.js"></script>
        <style>
            .big {
                border-radius:30px;
                position: relative;
                background-color: #75CDF9;
                width: 300px;
                height: 34px;
                margin-left: 30px;
                margin-top: 100px;
                line-height: 34px;
                text-align: center;
            }
            
            .hand {
                border-radius:30px;
                position: absolute;
                top: 0px;
                left: 0px;
                width: 40px;
                height: 32px;
                border: 1px solid #ccc;
                cursor: move;
            }
            
            .handler {
                background: #fff url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG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N0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6NGQ4ZTVmOTMtOTZiNC00ZTVkLThhY2ItN2U2ODhmMjE1NmU2Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+YiRG4AAAALFJREFUeNpi/P//PwMlgImBQkA9A+bOnfsIiBOxKcInh+yCaCDuByoswaIOpxwjciACFegBqZ1AvBSIS5OTk/8TkmNEjwWgQiUgtQuIjwAxUF3yX3xyGIEIFLwHpKyAWB+I1xGSwxULIGf9A7mQkBwTlhBXAFLHgPgqEAcTkmNCU6AL9d8WII4HOvk3ITkWJAXWUMlOoGQHmsE45ViQ2KuBuASoYC4Wf+OUYxz6mQkgwAAN9mIrUReCXgAAAABJRU5ErkJggg==") no-repeat center;
            }
            
            .handlerFinish {
                background: #fff url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA3hpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh7cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNS1jMDIxIDc5LjE1NTc3MiwgMjAxNC8wMS8xMy0xOTo0NDowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnM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0iZtA7AHEctDQ58MRuA6wlLgGFMoMpIG1QFeGwAIxGZo8GUhIysmwQGSAZgwHaEZhICIzOaBkJkqyM0CAAQDGx279Jf50AAAAAABJRU5ErkJggg==") no-repeat center;
            }
            
            .bg {
                border-radius:30px;
                background-color: #13CE66;
                height: 34px;
                width: 0px;
            }
            
            .text {
                position: absolute;
                top: 0px;
                width: 300px;
                -moz-user-select: none;
                -webkit-user-select: none;
                user-select: none;
                -o-user-select: none;
                -ms-user-select: none;
            }
        </style>

    </head>

    <body>

        <div id="app">
            <div class="big" >
                <div class="bg"></div>
                <div class="text">{{confirmWords}}</div>
                <div @mousedown="mousedownFn($event)" class="hand handler"></div>
            </div>

        </div>
        
        
    </body>
    
    <script>
        var vm = new Vue({
    
            el: "#app",
            name: '',
            components: {},
            props: {},
            data() {
                return {
                    beginClientX: 0,
                    mouseMoveStata: false,
                    maxwidth: 258,
                    confirmWords: '拖動滑塊驗證',
                    /*滑塊文字*/
                    confirmSuccess: false, /*是否成功*/
                }
            },
            created() {},
            watch: {
            },
            methods: {
                mousedownFn: function(e) {
                    this.mouseMoveStata = true;
                    this.beginClientX = e.clientX;
                }, 
                //按下滑塊
                successFunction() {
                    $(".hand").removeClass('handler').addClass('handlerFinish');
                    this.confirmWords = '驗證通過'
                    $(".big").css({
                        'color': '#fff'
                    });
                    $(".big").css({
                        'background-color': '#13CE66'
                    });
                    $(".hand").css({
                        'left': this.maxwidth
                    });
                    $(".bg").css({
                        'width': this.maxwidth
                    });
                    $('body').unbind('mousemove');
                    $('body').unbind('mouseup');
                    this.confirmSuccess = true;
                    
                } //判斷是否成功
            },
            mounted() {
                $('body').on('mousemove', (e) => {
                    //拖動使用箭頭指向Vue函數
                    if(this.mouseMoveStata) {
                        var width = e.clientX - this.beginClientX;
                        if(width > 0 && width <= this.maxwidth) {
                            $(".hand").css({
                                'left': width
                            });
                            $(".bg").css({
                                'width': width
                            });
                        } else if(width > this.maxwidth) {
                            this.successFunction();
                        }
                    }
                });
                $('body').on('mouseup', (e) => {
                    //鼠標放開 
                    this.mouseMoveStata = false;
                    var width = e.clientX - this.beginClientX;
                    if(width < this.maxwidth) {
                        $(".hand").css({
                            'left': 0
                        });
                        $(".bg").css({
                            'width': 0
                        });
                    }
                })
            }
        });
    </script>

</html>

感謝你能夠認真閱讀完這篇文章,希望小編分享的“Vue如何實現滑動驗證功能”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關注億速云行業資訊頻道,更多相關知識等著你來學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

vue
AI

新乐市| 界首市| 伊金霍洛旗| 防城港市| 尤溪县| 湘西| 华宁县| 佛山市| 阿巴嘎旗| 乐昌市| 霍林郭勒市| 仁怀市| 庆安县| 保靖县| 云阳县| 游戏| 祁门县| 宾阳县| 石屏县| 夹江县| 临潭县| 全州县| 九寨沟县| 泾川县| 大同县| 巩留县| 乐山市| 东兰县| 西平县| 洞头县| 巴彦县| 甘德县| 苍梧县| 万全县| 剑川县| 鄂托克前旗| 孟连| 阜新| 金堂县| 承德县| 新郑市|