Vue可左右滑动按钮组组件使用详解
更新时间:2022年2月27日 22:19 点击:832 作者:觅长生
本文实例为大家分享了基于Vue可左右滑动按钮组组件,供大家参考,具体内容如下
左右两箭头控制按钮组左右移动,双击到最左或最右边,功能比较简单。如下所示
<template> <div class="demoButtons"> <div class="buttonF"> <el-row style="height:30px "> <el-col class="lableI"><i class="el-icon-arrow-left " @click="moveButtons('left')" @dblclick="moveSide('left')" /></el-col> <el-col ref="buttonBody" class="buttonBody"> <el-row id="buttonRow" ref="buttonRow"> <el-tag :style="{'width':buttonWidth+'px'}" v-for="(item, index) in buttonData" :key="index" :type="index == clickIndex ? '' : 'info'" @click="resetData(index, item)"> <el-tooltip v-if="item.name && item.name.length > parseInt(buttonWidth/12) - 1" placement="top" :content="item.name" effect="light"> <span>{{ resetName(item.name) }}</span> </el-tooltip> <span v-else>{{ item.name }}</span> </el-tag> </el-row> </el-col> <el-col class="lableI"><i class="el-icon-arrow-right " @click="moveButtons('right')" @dblclick="moveSide('right')" /></el-col> </el-row> </div> </div> </template> <script> import $ from 'jquery' export default { props: { buttonData: { type: Array, default: () => { return [] } }, buttonWidth: { type: Number, default: 62 } }, data () { return { clickIndex: 0, currentSite: 0, showCount: 0, clickTimer: null, } }, watch: {}, created () { // this.setButtons() }, mounted () { this.$nextTick(() => { this.showCount = parseInt(this.$refs.buttonBody.$el.clientWidth / this.buttonWidth) // 一行能展示几个按钮 }) }, methods: { //设置名字 resetName (val) { let i = parseInt(this.buttonWidth / 12) - 1; if (val && val.length > i) { return val.slice(0, i) } else { return val } }, // 单击移一格 moveButtons (val) { if (this.clickTimer) { window.clearTimeout(this.clickTimer) this.clickTimer = null } this.clickTimer = window.setTimeout(() => { this.$nextTick(() => { if (val == 'left') { if (this.currentSite < 0) { this.currentSite = this.currentSite + this.buttonWidth } } else { const totalCount = this.buttonData.length // 总共几个按钮 const showIndex = -parseInt(this.currentSite / this.buttonWidth) // 向左移了几个按钮 console.log(totalCount, 'totalLength', this.showCount, showIndex) if (showIndex + this.showCount < totalCount) { this.currentSite = this.currentSite - this.buttonWidth } } $('#buttonRow').animate({ marginLeft: this.currentSite + 'px' }) }) }, 300) }, // 双击到边 moveSide (val) { if (this.clickTimer) { window.clearTimeout(this.clickTimer) this.clickTimer = null } this.$nextTick(() => { if (val == 'left') { this.currentSite = 0 } else { const totalCount = this.buttonData.length // 总共几个按钮 if (totalCount > this.showCount) { this.currentSite = -((totalCount - this.showCount) * this.buttonWidth) } } $('#buttonRow').animate({ marginLeft: this.currentSite + 'px' }) }) }, setButtons (data) { this.buttonData = data }, resetData (index, data) { this.clickIndex = index this.$emit('resetData', data) } } } </script> <style lang="scss" scoped> .demoButtons { width: 100%; height: 100%; } .buttonF { width: 100%; margin: 0 auto; height: 30px; line-height: 30px; } .lableI { height: 30px; line-height: 30px; width: 20px; cursor: pointer; } .buttonBody { overflow: hidden; height: 30px; line-height: 30px; width: calc(100% - 40px); white-space: nowrap; } .el-tag { text-align: center; padding: 0px 8px !important; height: 28px; line-height: 28px; cursor: pointer; border-radius: 0px !important; overflow: hidden; font-size: 12px; } </style>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持猪先飞。
原文出处:https://blog.csdn.net/qq_42872836/article/details/117740295
上一篇: Vue实现时间轴功能
下一篇: Vue标尺插件使用详解
相关文章
- 这篇文章主要介绍了vue中activated的用法,帮助大家更好的理解和使用vue框架,感兴趣的朋友可以了解下...2021-01-03
基于vue-simple-uploader封装文件分片上传、秒传及断点续传的全局上传插件功能
这篇文章主要介绍了基于vue-simple-uploader封装文件分片上传、秒传及断点续传的全局上传插件,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-02-23Antd-vue Table组件添加Click事件,实现点击某行数据教程
这篇文章主要介绍了Antd-vue Table组件添加Click事件,实现点击某行数据教程,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-17- 这篇文章主要介绍了Vue基于localStorage存储信息代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-11-16
- 这篇文章主要介绍了vue 监听 Treeselect 选择项的改变操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-09-01
- 这篇文章主要介绍了vue 实现动态路由的方法,文中示例代码非常详细,帮助大家更好的理解和学习,感兴趣的朋友可以了解下...2020-07-06
- 这篇文章主要介绍了Vue组件跨层级获取组件操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-07-28
- 这篇文章主要介绍了vue 获取到数据但却渲染不到页面上的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-11-19
antdesign-vue结合sortablejs实现两个table相互拖拽排序功能
这篇文章主要介绍了antdesign-vue结合sortablejs实现两个table相互拖拽排序功能,本文通过实例图文相结合给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-01-09vuejs element table 表格添加行,修改,单独删除行,批量删除行操作
这篇文章主要介绍了vuejs element table 表格添加行,修改,单独删除行,批量删除行操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-07-18- 这篇文章主要介绍了vue treeselect获取当前选中项的label实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-09-01
- 这篇文章主要给大家介绍了关于Vue中slot-scope的深入理解,这个教程非常适合初学者,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-04-17
- 最常见的多环境配置,就是开发环境配置,和生产环境配置,本文主要介绍了vue项目多环境配置的实现,感兴趣的可以了解一下...2021-07-20
- 下面小编就为大家带来一篇利用JS实现点击按钮后图片自动切换的简单方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2016-10-25
vue项目页面嵌入代码块vue-prism-editor的实现
这篇文章主要介绍了vue项目页面嵌入代码块vue-prism-editor的实现,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-10-30- 这篇文章主要介绍了Vue 3.0 中 jsx 语法使用,帮助大家更好的理解和使用vue框架,感兴趣的朋友可以了解下...2020-11-13
- 这篇文章主要为大家详细介绍了vue实现同时设置多个倒计时,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-05-20
vue Treeselect下拉树只能选择第N级元素实现代码
这篇文章主要介绍了vue Treeselect下拉树只能选择第N级元素实现代码,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-09-01解决vue的router组件component在import时不能使用变量问题
这篇文章主要介绍了解决vue的router组件component在import时不能使用变量问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-07-27Ant design vue table 单击行选中 勾选checkbox教程
这篇文章主要介绍了Ant design vue table 单击行选中 勾选checkbox教程,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-10-25