最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501
当前位置: 首页 - 科技 - 知识百科 - 正文

vue实现一拉到底的滑动验证

来源:懂视网 责编:小OO 时间:2020-11-27 21:53:18
文档

vue实现一拉到底的滑动验证

本文实例为大家分享了vue实现简单的一拉到底的滑动验证的具体代码,供大家参考,具体内容如下:直接上代码;,this.mouseMoveFn);document.getElementsByTagName('html')[0].removeEventListener('mouseup',this.moseUpFn);}else { document.getElementsByTagName('html')[0].removeEventListener('mouseup',this.mouseMoveFn);document.getElementsByTagName('html')[0].addEventListener('mouseup'。
推荐度:
导读本文实例为大家分享了vue实现简单的一拉到底的滑动验证的具体代码,供大家参考,具体内容如下:直接上代码;,this.mouseMoveFn);document.getElementsByTagName('html')[0].removeEventListener('mouseup',this.moseUpFn);}else { document.getElementsByTagName('html')[0].removeEventListener('mouseup',this.mouseMoveFn);document.getElementsByTagName('html')[0].addEventListener('mouseup'。

本文实例为大家分享了vue实现简单的一拉到底的滑动验证的具体代码,供大家参考,具体内容如下

直接上代码

<template>
 <div class="drag" ref="dragDiv">
 <div class="drag_bg"></div>
 <div class="drag_text">{{confirmWords}}</div>
 <div ref="moveDiv" @mousedown="mousedownFn($event)" :class="{'handler_ok_bg':confirmSuccess}" class="handler handler_bg" style="position: absolute;top: 0px;left: 0px;"></div>
 </div>
</template>

<script>
 export default {
 data(){
 return {
 beginClientX:0, /*距离屏幕左端距离*/
 mouseMoveStata:false, /*触发拖动状态 判断*/
 maxwidth:'', /*拖动最大宽度,依据滑块宽度算出来的*/
 confirmWords:'拖动滑块验证', /*滑块文字*/
 confirmSuccess:false /*验证成功判断*/
 }
 },
 methods: {
 mousedownFn:function (e) {
 if(!this.confirmSuccess){
 e.preventDefault && e.preventDefault(); //阻止文字选中等 浏览器默认事件
 this.mouseMoveStata = true;
 this.beginClientX = e.clientX;
 }
 }, //mousedoen 事件
 successFunction(){
 this.confirmSuccess = true
 this.confirmWords = '验证通过';
 if(window.addEventListener){
 document.getElementsByTagName('html')[0].removeEventListener('mousemove',this.mouseMoveFn);
 document.getElementsByTagName('html')[0].removeEventListener('mouseup',this.moseUpFn);
 }else {
 document.getElementsByTagName('html')[0].removeEventListener('mouseup',()=>{});
 }
 document.getElementsByClassName('drag_text')[0].style.color = '#fff'
 document.getElementsByClassName('handler')[0].style.left = this.maxwidth + 'px';
 document.getElementsByClassName('drag_bg')[0].style.width = this.maxwidth + 'px';
 }, //验证成功函数
 mouseMoveFn(e){
 if(this.mouseMoveStata){
 let width = e.clientX - this.beginClientX;
 if(width>0 && width<=this.maxwidth){
 document.getElementsByClassName('handler')[0].style.left = width + 'px';
 document.getElementsByClassName('drag_bg')[0].style.width = width + 'px';
 }else if(width>this.maxwidth){
 this.successFunction();
 }
 }
 }, //mousemove事件
 moseUpFn(e){
 this.mouseMoveStata = false;
 var width = e.clientX - this.beginClientX;
 if(width<this.maxwidth){
 document.getElementsByClassName('handler')[0].style.left = 0 + 'px';
 document.getElementsByClassName('drag_bg')[0].style.width = 0 + 'px';
 }
 } //mouseup事件
 },
 mounted(){
 this.maxwidth = this.$refs.dragDiv.clientWidth - this.$refs.moveDiv.clientWidth;
 document.getElementsByTagName('html')[0].addEventListener('mousemove',this.mouseMoveFn);
 document.getElementsByTagName('html')[0].addEventListener('mouseup',this.moseUpFn)
 }
 }
</script>

<style scoped>
 .drag{
 position: relative;
 background-color: #e8e8e8;
 width: 100%;
 height: 34px;
 line-height: 34px;
 text-align: center;
 }
 .handler{
 width: 40px;
 height: 32px;
 border: 1px solid #ccc;
 cursor: move;
 }
 .handler_bg{
 background: #fff url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA3hpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNS1jMDIxIDc5LjE1NTc3MiwgMjAxNC8wMS8xMy0xOTo0NDowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo0ZDhlNWY5My05NmI0LTRlNWQtOGFjYi03ZTY4OGYyMTU2ZTYiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NTEyNTVEMURGMkVFMTFFNEI5NDBCMjQ2M0ExMDQ1OUYiIHhtcE1NOkluc3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wAoEZ+IDUPiIMY8IN1QJwENOgj3ACo5gNAbMBAHLgAxA4gQ5igAnNJ0MwAVTsX7IKyY7L2UNuJAf+AmAmJ78AEDTBiwGYg5gbifCSxFCZoaBMCy4A4GOjnH0D6DpK4IxNSVIHAfSDOAeLraJrjgJp/AwPbHMhejiQnwYRmUzNQ4VQgDQqXK0ia/0I17wJiPmQNTNBEAgMlQIWiQA2vgWw7QppBekGxsAjIiEUSBNnsBDWEAY9mEFgMMgBk00E0iZtA7AHEctDQ58MRuA6wlLgGFMoMpIG1QFeGwAIxGZo8GUhIysmwQGSAZgwHaEZhICIzOaBkJkqyM0CAAQDGx279Jf50AAAAAABJRU5ErkJggg==") no-repeat center;
 }
 .drag_bg{
 background-color: #7ac23c;
 height: 34px;
 width: 0px;
 }
 .drag_text{
 position: absolute;
 top: 0px;
 width: 100%;text-align: center;
 -moz-user-select: none;
 -webkit-user-select: none;
 user-select: none;
 -o-user-select:none;
 -ms-user-select:none;
 }
</style>

声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文档

vue实现一拉到底的滑动验证

本文实例为大家分享了vue实现简单的一拉到底的滑动验证的具体代码,供大家参考,具体内容如下:直接上代码;,this.mouseMoveFn);document.getElementsByTagName('html')[0].removeEventListener('mouseup',this.moseUpFn);}else { document.getElementsByTagName('html')[0].removeEventListener('mouseup',this.mouseMoveFn);document.getElementsByTagName('html')[0].addEventListener('mouseup'。
推荐度:
标签: 验证 VUE 滑块
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top