效果图:

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【原创】下划线动态效果按钮,一般按钮模式,开关切换模式的更多相关文章

  1. UI-切圆角、透明度、取消按钮点击高亮效果、按钮文字带下划线

    一.切UIView的某个角为圆角 如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架).而若要指定某 ...

  2. 实现按钮跳转&下划线等

    按钮点击跳转页面:(在java文件里写) 1 public class MainActivity extends AppCompatActivity { 2 3 private Button mbtn ...

  3. atitit.按钮光标滑过高亮切换以及其他动态效果的实现css html js --attilax总结

    atitit.按钮光标滑过高亮切换以及其他动态效果的实现css html  js --attilax总结 4. 鼠标越过动态图片切换实现 1 4.1. 优先模式::css模式... 1 4.2. 其次 ...

  4. _ 下划线 vue mixins 混入 变量前有下划线 变量不起作用

    _ 下划线 vue mixins 混入 变量前有下划线 变量不起作用

  5. Textview下划线注册用户跳转实现

    在xml中: <TextView android:id="@+id/textView_regtext" android:layout_width="wrap_con ...

  6. Android 如何自定义EditText 下划线?

    项目要求: 笔者曾经做过一个项目,其中登录界面的交互令人印象深刻.交互设计师给出了一个非常作的设计,要求做出包含根据情况可变色的下划线,左侧有可变图标,右侧有可变删除标志的输入框,如图 记录制作过程: ...

  7. UILabletext去掉乱码 控制颜色 行高 自定义大小 。显示不同的字体颜色、字体大小、行间距、首行缩进、下划线等属性(NSMutableAttributedString)

    text去掉乱码 设置不同颜色 行高 自定义大小 #import <Foundation/Foundation.h> @interface TextsForRow : NSObject @ ...

  8. Vue框架下的node.js安装教程

    Vue框架下的node.js安装教程 python服务器.php  ->aphche.java ->tomcat.   iis -->它是一个可以运行JAVASCRIPTR 的运行环 ...

  9. Button的几种常用的xml背景,扁平化,下划线,边框包裹,以及按压效果

    Button的几种常用的xml背景,扁平化,下划线,边框包裹,以及按压效果 分享下我项目中用到的几种Button的效果,说实话,还真挺好看的 一.标准圆角 效果是这样的 他的实现很简单,我们只需要两个 ...

  10. Android开发 ---SQLite数据库,lock文件,结果集游标,适配器,安全退出,给连接设置下划线,编辑器,投影,ContentValues存储,DbHelper,activity栈

    目录截图: 1.activity_main.xml 主界面效果: <?xml version="1.0" encoding="utf-8"?> &l ...

随机推荐

  1. 2023-05-18:有 n 名工人。 给定两个数组 quality 和 wage , 其中,quality[i] 表示第 i 名工人的工作质量,其最低期望工资为 wage[i] 。 现在我们想雇佣

    2023-05-18:有 n 名工人. 给定两个数组 quality 和 wage , 其中,quality[i] 表示第 i 名工人的工作质量,其最低期望工资为 wage[i] . 现在我们想雇佣 ...

  2. LLM探索:环境搭建与模型本地部署

    前言 最近一直在炼丹(搞AIGC这块),突然发现业务代码都索然无味了- 上次发了篇AI画图的文章,ChatGPT虽然没法自己部署,但现在开源的LLM还是不少的,只要有一块差不多的显卡,要搞个LLM本地 ...

  3. vue-router几大坑

    如今vue使用率很高,踩坑这就是很平常的了,使用了几年坑都依然没踩完,纠结呀 一.router.js配置要点 大家都知道vue 是组件化开发,页面很多路由难免, 这里是路由配置router.js 最外 ...

  4. nodejs 中 stream.pipe()直接将文件输出到页面乱码

    最近仿照anywhere写个anyentry目录读取器,发现使用stream.pipe()将文件输入到页面时,出现中文乱码 看哇 看到着实不爽,不解决咋能算 于是开始寻找问题根源 一.配置encodi ...

  5. 一分钟学一个 Linux 命令 - pwd

    前言 大家好,我是 god23bin.欢迎大家继续围观<一分钟学一个 Linux 命令>,每天只需一分钟,记住一个 Linux 命令不成问题.本篇文章将聚焦于 pwd 命令,一个超级简单又 ...

  6. 在 Linux 和 Windows 下源码安装 Perl

    Perl 是一种功能丰富的计算机程序语言,运行在超过 100 种计算机平台上,适用广泛,从大型机到便携设备,从快速原型创建到大规模可扩展开发.在生物信息分析领域,Perl 主要是做数据预处理.文本处理 ...

  7. Linq的所有用法(简单化)

    Linq 是一种强大的查询语言,可以过滤.排序和组合各种数据源.下面我们将讨论 Linq 的各种用法. Linq 的基本语法: Linq 可以应用于任何对象集合,以下是一个示例: var number ...

  8. GPT3的性能评估:比较不同语言、文本和任务的差异

    目录 GPT-3 性能评估:比较不同语言.文本和任务的差异 近年来,自然语言处理 (NLP) 和人工智能领域取得了巨大的进展,其中 GPT-3 是目前最为先进的语言模型之一.GPT-3 拥有超过 17 ...

  9. 记录一个在写项目中遇到的Maven依赖无法导入的问题

    记录一个在写项目中遇到的Maven依赖无法导入的问题 项目是一个父项目做依赖管理,三个子项目,今天遇到一个问题: 子项目中导入的依赖,怎么都导入不进去,maven仓库中已经有了,idea提示也没有问题 ...

  10. PostgreSQL 12 文档: 部分 II. SQL 语言

    部分 II. SQL 语言 这部份描述在PostgreSQL中SQL语言的使用.我们从描述SQL的一般语法开始,然后解释如何创建保存数据的结构.如何填充数据库以及如何查询它.中间的部分列出了在SQL命 ...