Files
frost-navigation/src/components/FloatingBtn.vue

201 lines
4.4 KiB
Vue
Raw Normal View History

2021-06-14 00:38:26 +08:00
<template>
<div class="floating-btn">
<div class="btns-inner">
2021-06-14 14:24:18 +08:00
<button class="btn" type="button" title="折叠侧边菜单" @click="toggleSideCollapse()">
2021-06-14 00:38:26 +08:00
<i class="el-icon-menu" aria-hidden="true"></i>
2021-06-14 14:24:18 +08:00
</button>
<button class="btn" type="button" title="刷新" @click="refreshPage()">
2021-06-14 00:38:26 +08:00
<i class="el-icon-refresh-right" aria-hidden="true"></i>
2021-06-14 14:24:18 +08:00
</button>
<button class="btn" type="button" title="返回主页" @click="backToHome()">
2021-06-14 00:38:26 +08:00
<i class="el-icon-s-home" aria-hidden="true"></i>
2021-06-14 14:24:18 +08:00
</button>
2021-06-14 00:38:26 +08:00
</div>
<div class="btns-outer">
2021-06-14 14:24:18 +08:00
<button class="btn" type="button" title="菜单">
2021-06-14 00:38:26 +08:00
<i class="fa fa-bars" aria-hidden="true"></i>
2021-06-14 14:24:18 +08:00
</button>
2021-06-14 00:38:26 +08:00
</div>
</div>
</template>
<script>
export default {
name: 'FloatingBtn',
data() {
return {
config: this.$root.config.storage
}
},
2021-06-14 14:24:18 +08:00
mounted () {
this.initAnimation();
},
2021-06-14 00:38:26 +08:00
methods: {
2021-06-14 14:24:18 +08:00
/**
* 设置动画
*/
initAnimation() {
var btns = document.querySelectorAll('.floating-btn .btn');
var className = 'animate';
btns.forEach((elem) => {
elem.onclick = function () {
this.classList.remove(className);
setTimeout(() => {
this.classList.add(className);
}, 20);
};
});
},
2021-06-14 00:38:26 +08:00
/**
* 返回主页
*/
backToHome() {
var routeName = 'Home';
if (this.$route.name != routeName) {
this.$router.push({
name: routeName
}).then(() => {
window.location.reload();
});
} else {
this.$message({
duration: 2000,
message: '已经在主页啦~',
type: 'warning'
});
}
},
/**
* 刷新
*/
refreshPage() {
window.location.reload();
},
/**
* 切换侧边菜单折叠状态
*/
toggleSideCollapse() {
var cfg = this.config;
cfg.sideMenuCollapse = !cfg.sideMenuCollapse;
},
},
}
</script>
<style lang="less" scoped>
.floating-btn {
position: fixed;
z-index: 5000;
right: 2rem;
bottom: 2rem;
text-align: center;
&:hover {
.btns-inner .btn {
2021-06-14 14:24:18 +08:00
width: 2.6rem;
height: 2.6rem;
font-size: 1rem;
2021-06-14 00:38:26 +08:00
}
}
}
.btns-inner {
display: inline-block;
.btn {
width: 0;
height: 0;
background-color: @colorSecondary;
font-size: 0;
2021-06-14 14:24:18 +08:00
transition: all calc(@transitionTime * 1.6),
font-size calc(@transitionTime * 0.8);
2021-06-14 00:38:26 +08:00
&:not(:first-child) {
margin-top: 0.75rem;
}
}
}
.btns-outer {
display: block;
.btn {
margin-top: 1rem;
2021-06-14 14:24:18 +08:00
width: 3.2rem;
height: 3.2rem;
2021-06-14 00:38:26 +08:00
background-color: @colorPrimary;
}
}
.btn {
display: flex;
align-items: center;
justify-content: center;
position: relative;
right: 0;
bottom: 0;
box-shadow: 0 0.15rem 0.15rem 0 rgba(0, 0, 0, 0.14),
0 0.2rem 0.1rem -0.15rem rgba(0, 0, 0, 0.12),
0 0.1rem 0.3rem 0 rgba(0, 0, 0, 0.20);
border-radius: 50%;
font-size: 1rem;
color: #FFF;
overflow: hidden;
cursor: pointer;
2021-06-14 14:24:18 +08:00
&::before, &::after {
2021-06-14 00:38:26 +08:00
content: "";
display: block;
position: absolute;
2021-06-14 14:24:18 +08:00
top: 50%;
left: 50%;
2021-06-14 00:38:26 +08:00
width: 100%;
height: 100%;
2021-06-14 14:24:18 +08:00
border-radius: 50%;
2021-06-14 00:38:26 +08:00
background-color: #FFF;
opacity: 0;
2021-06-14 14:24:18 +08:00
transition: opacity @transitionTime;
transform: translate(-50%, -50%);
}
&:hover::before {
opacity: 0.1;
}
&.animate::after {
animation: floatingBtnClick 0.5s linear;
2021-06-14 00:38:26 +08:00
}
2021-06-14 14:24:18 +08:00
}
2021-06-14 00:38:26 +08:00
2021-06-14 14:24:18 +08:00
@keyframes floatingBtnClick {
0% {
width: 0;
height: 0;
opacity: 0;
}
25% {
2021-06-14 00:38:26 +08:00
opacity: 0.2;
}
2021-06-14 14:24:18 +08:00
50% {
width: 100%;
height: 100%;
}
75% {
opacity: 0.2;
}
100% {
width: 100%;
height: 100%;
opacity: 0;
}
2021-06-14 00:38:26 +08:00
}
</style>