Vue【原创】下划线动态效果按钮,一般按钮模式,开关切换模式
效果图:

1.icon-button 一般按钮模式:
1 <template>
2 <div class="icon-button" :style="{ color: font.color }" @click="onclick">
3 <i :class="[icon.type]" :style="{ color: icon.color, fontSize: icon.size }" class="right" v-if="showIcon"></i>
4 <slot>
5 <span class="text" :style="{ fontSize: font.size }">{{ title }}</span>
6 </slot>
7 </div>
8 </template>
9
10 <script>
11 export default {
12 name: 'LiloIconButton',
13 props: {
14 title: {
15 type: String,
16 default: '',
17 required: false
18 },
19 showIcon: {
20 type: Boolean,
21 default: true
22 },
23 icon: {
24 type: Object,
25 default() {
26 return {
27 type: 'el-icon-setting',
28 size: '1em',
29 color: '#00417a'
30 };
31 },
32 required: false
33 },
34 font: {
35 type: Object,
36 default() {
37 return {
38 size: '1em',
39 color: '#00417a'
40 };
41 },
42 required: false
43 }
44 },
45 data() {
46 return {
47 selected: true
48 };
49 },
50 methods: {
51 onclick() {
52 this.selected = !this.selected;
53 this.$emit('toggle', this.selected);
54 }
55 }
56 };
57 </script>
58
59 <style lang="scss" scoped>
60
61 $blue: #00417a;
62
63 .icon-button {
64 -webkit-transition: all 0.3s ease 0s;
65 transition: all 0.3s ease 0s;
66 cursor: pointer;
67 text-align: center;
68 display: inline-block;
69 -moz-user-select: none;
70 -webkit-user-select: none;
71 user-select: none;
72 .right{
73 margin-right: 3px;
74 }
75 &:after {
76 content: ' ';
77 // position: absolute;
78 z-index: 2;
79 // bottom: -5px;
80 margin-left: 50%;
81 margin-top: 2px;
82 display: block;
83 width: 100%;
84 height: 2px;
85 transform: translate(-50%);
86 }
87 &:hover:after {
88 height: 2px;
89 animation: add_width 0.2s ease forwards;
90 background: $blue;
91 }
92 @keyframes add_width {
93 from {
94 width: 0;
95 }
96 to {
97 width: 100%;
98 }
99 }
100 .text {
101 letter-spacing: 1px;
102 }
103 }
104 </style>
2.icon-switcher 开关切换按钮模式:
1 <template>
2 <div class="icon-switcher" :style="{ color: font.color }" :class="[selected ? 'active' : 'deactive']" @click="onclick">
3 <i :class="[icon.type]" :style="{ color: icon.color, fontSize: icon.size }" class="right"></i>
4 <slot>
5 <span class="text" :style="{ fontSize: font.size }">{{ title }}</span>
6 </slot>
7 </div>
8 </template>
9
10 <script>
11 export default {
12 name: 'LiloIconSwitcher',
13 props: {
14 title: {
15 type: String,
16 default: '',
17 required: false
18 },
19 icon: {
20 type: Object,
21 default() {
22 return {
23 type: 'el-icon-setting',
24 size: '1em',
25 color: '#00417a'
26 };
27 },
28 required: false
29 },
30 font: {
31 type: Object,
32 default() {
33 return {
34 size: '1em',
35 color: '#00417a'
36 };
37 },
38 required: false
39 },
40 checked: {
41 type: Boolean,
42 default: false,
43 required: false
44 }
45 },
46 data() {
47 return {
48 selected: this.checked
49 };
50 },
51 methods: {
52 onclick() {
53 this.selected = !this.selected;
54 this.$emit('toggle', this.selected);
55 }
56 }
57 };
58 </script>
59
60 <style lang="scss" scoped>
61
62 $blue: #00417a;
63
64 .icon-switcher {
65 -webkit-transition: all 0.3s ease 0s;
66 transition: all 0.3s ease 0s;
67 cursor: pointer;
68 text-align: center;
69 display: inline-block;
70 -moz-user-select: none;
71 -webkit-user-select: none;
72 user-select: none;
73 .right {
74 margin-right: 3px;
75 }
76 &.active {
77 &:after {
78 content: ' ';
79 z-index: 2;
80 margin-left: 50%;
81 margin-top: 2px;
82 display: block;
83 width: 100%;
84 height: 2px;
85 transform: translate(-50%);
86 background: $blue;
87 }
88 }
89 &.deactive {
90 &:after {
91 content: ' ';
92 z-index: 2;
93 margin-left: 50%;
94 margin-top: 2px;
95 display: block;
96 width: 100%;
97 height: 2px;
98 transform: translate(-50%);
99 }
100 }
101 &:hover:after {
102 height: 2px;
103 animation: add_width 0.2s ease forwards;
104 background: $blue;
105 }
106 @keyframes add_width {
107 from {
108 width: 0;
109 }
110 to {
111 width: 100%;
112 }
113 }
114 .text {
115 letter-spacing: 1px;
116 }
117 }
118
119 </style>
调用示例:
1 <div class="mt-10">
2 <lilo-icon-button class="mr-10" title="简单按钮"></lilo-icon-button>
3 <lilo-icon-button class="mr-10"><span>我是一个插槽</span></lilo-icon-button>
4 <lilo-icon-button
5 class="mr-10"
6 title="自定义按钮"
7 :icon="{ type: 'el-icon-upload', color: '#f56c6c', size: '1rem' }"
8 :font="{ color: '#5500ff', size: '1rem' }"
9 @toggle="toggle"
10 ></lilo-icon-button>
11 <lilo-icon-button class="mr-10" :showIcon="false"><span>不需要图标</span></lilo-icon-button>
12 </div>
13 <div class="mt-10">
14 <lilo-icon-switcher class="mr-10" title="切换按钮"></lilo-icon-switcher>
15 <lilo-icon-switcher class="mr-10"><span>我也是一个插槽</span></lilo-icon-switcher>
16 <lilo-icon-switcher
17 class="mr-10"
18 title="自定义切换按钮"
19 :icon="{ type: 'el-icon-loading', color: '#005500', size: '1rem' }"
20 :font="{ color: '#5500ff', size: '1rem' }"
21 :checked="true"
22 @toggle="toggle"
23 ></lilo-icon-switcher>
24 <lilo-icon-button class="mr-10" :showIcon="false"><span>不需要图标</span></lilo-icon-button>
25 </div>
Vue【原创】下划线动态效果按钮,一般按钮模式,开关切换模式的更多相关文章
- UI-切圆角、透明度、取消按钮点击高亮效果、按钮文字带下划线
一.切UIView的某个角为圆角 如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架).而若要指定某 ...
- 实现按钮跳转&下划线等
按钮点击跳转页面:(在java文件里写) 1 public class MainActivity extends AppCompatActivity { 2 3 private Button mbtn ...
- atitit.按钮光标滑过高亮切换以及其他动态效果的实现css html js --attilax总结
atitit.按钮光标滑过高亮切换以及其他动态效果的实现css html js --attilax总结 4. 鼠标越过动态图片切换实现 1 4.1. 优先模式::css模式... 1 4.2. 其次 ...
- _ 下划线 vue mixins 混入 变量前有下划线 变量不起作用
_ 下划线 vue mixins 混入 变量前有下划线 变量不起作用
- Textview下划线注册用户跳转实现
在xml中: <TextView android:id="@+id/textView_regtext" android:layout_width="wrap_con ...
- Android 如何自定义EditText 下划线?
项目要求: 笔者曾经做过一个项目,其中登录界面的交互令人印象深刻.交互设计师给出了一个非常作的设计,要求做出包含根据情况可变色的下划线,左侧有可变图标,右侧有可变删除标志的输入框,如图 记录制作过程: ...
- UILabletext去掉乱码 控制颜色 行高 自定义大小 。显示不同的字体颜色、字体大小、行间距、首行缩进、下划线等属性(NSMutableAttributedString)
text去掉乱码 设置不同颜色 行高 自定义大小 #import <Foundation/Foundation.h> @interface TextsForRow : NSObject @ ...
- Vue框架下的node.js安装教程
Vue框架下的node.js安装教程 python服务器.php ->aphche.java ->tomcat. iis -->它是一个可以运行JAVASCRIPTR 的运行环 ...
- Button的几种常用的xml背景,扁平化,下划线,边框包裹,以及按压效果
Button的几种常用的xml背景,扁平化,下划线,边框包裹,以及按压效果 分享下我项目中用到的几种Button的效果,说实话,还真挺好看的 一.标准圆角 效果是这样的 他的实现很简单,我们只需要两个 ...
- Android开发 ---SQLite数据库,lock文件,结果集游标,适配器,安全退出,给连接设置下划线,编辑器,投影,ContentValues存储,DbHelper,activity栈
目录截图: 1.activity_main.xml 主界面效果: <?xml version="1.0" encoding="utf-8"?> &l ...
随机推荐
- python爬虫防止IP被封的一些措施(转)
python爬虫防止IP被封的一些措施(转) 在编写爬虫爬取数据的时候,因为很多网站都有反爬虫措施,所以很容易被封IP,就不能继续爬了.在爬取大数据量的数据时更是瑟瑟发抖,时刻担心着下一秒IP可能就被 ...
- Python这样读写Excel数据,这样简直不要太粗暴!
什么是xlrd&xlwt? xlrd和xlwt是Python语言中,读取和写入Excel数据的扩展工具.xlrd为xls文件read库,xlwt为xls文件write库.具体请看xlrd百度百 ...
- 【CF】掉分总结
比赛总结 前情提要 自从前段时间连续掉分,就心态崩了,还是自己太菜,一直想写个总结,看看这几场比赛都干了啥,以后准备怎么办.鸽了这么久的总结,是该写写了. 这是正文 首先大致提一下情感曲线(菜的真实) ...
- 欢迎来到farter的可能是最后一个用于博客的地方【
目前先把公告栏里放一堆链接作为导航了(手机上竟然没有公告栏??? 准备从新浪博客往这里迁,整活可能也在这里? 还是复制一份公告栏的链接库吧( 歌声合成相关文章 敝个人站(好用好玩都在这) 敝渣浪博客( ...
- Vue——表单控制、购物车案例、v-model进阶、与后端交互三种方式、箭头函数
表单控制 // 1 checkbox 单选 多选 // 2 radio 单选 <body> <div id="app"> <h1>checkbo ...
- @Target元注解的使用
@Target注解标记另外的注解用于限制此注解可以应用哪种Java元素类型.先看Java SE 8中@Target是如何声明的: package java.lang.annotation; publi ...
- 将HTML网页转换为Markdown格式的工具及方法
保存博客文章 早期在markdown语法还没有推出来之前,编写blog是在网页上或olw写的,也就是文章是保存在对方的主机上. 最近计划把我在博客园的一些早期html文章转换成markdown的文件, ...
- 【python基础】函数-模块
函数的优点之一是,使用它们可将代码块与主程序分离.通过给函数指定函数名称,可让主程序容易理解的多.我们还可以更加细化,将函数存储在被称为模块的独立文件中,再将模块导入到主程序中.import关键字作用 ...
- HiveSQL在使用聚合类函数的时候性能分析和优化详解
概述 前文我们写过简单SQL的性能分析和解读,简单SQL被归类为select-from-where型SQL语句,其主要特点是只有map阶段的数据处理,相当于直接从hive中取数出来,不需要经过行变化. ...
- ASIC加速技术在ASIC加速性能优化中的新应用与挑战
目录 1. 引言 2. 技术原理及概念 3. 实现步骤与流程 4. 应用示例与代码实现讲解 5. 优化与改进 1. 引言 随着计算机技术的发展,芯片的性能和面积都得到了极大的提升.为了进一步提高芯片的 ...