May 29, 2021 Article blog
Today's W3Cschool combo gives you how to use css cube-bezier functions to make dynamic buffering effects? Cubic-bezier, a three-time Bezier, can generate bezier curves, mainly in css, speed curves that provide transition effects for transition and animation.
The cubic-bezier function accepts four parameters by default, cubic-bezier (x1, y1, x2, y2), where y1, y2 can be greater than or less than 0, based on which some buffer transition effect can be made.
<template>
<div class="menu">
<div v-for="item in menuList">
<div class="menu-item" @mouseover="mouseover($event, item)" @mouseleave="mouseleave">{{ item.name }}</div>
</div>
</div>
<transition name="move">
<div id="sub-menu" ref="subMenu" v-show="show" @mousemove="overSub">
<div class="sub-menu-item" v-for="item in subMenuList">
{{ item.name }}
</div>
</div>
</transition>
</template>
<script>
import { ref } from ‘vue‘;
export default {
setup() {
let menuList = ref([
{
name: ‘cloud‘,
children: [
{
name: ‘cloud1‘
},
{
name: ‘cloud2‘
}
]
},
{
name: ‘software‘,
children: [
{
name: ‘software1‘
},
{
name: ‘software2‘
},
{
name: ‘software3‘
}
]
},
{
name: ‘docs‘,
children: [
{
name: ‘docs1‘
},
{
name: ‘docs2‘
}
]
}
]);
let subMenuList = ref([]);
let show = ref(false);
return { menuList, subMenuList, show };
},
methods: {
mouseover(e, item) {
this.subMenuList = item.children;
this.$refs.subMenu.style.left = e.target.offsetLeft + ‘px‘;
this.$refs.subMenu.style.height = `${43 * this.subMenuList.length}px`;
this.show = true;
},
mouseleave() {
this.show = false;
}
}
};
</script>
<style scoped>
.menu {
display: flex;
}
.menu-item {
height: 40px;
width: fit-content;
margin-left: 20px;
font-size: 26px;
font-weight: lighter;
color: #aaa;
cursor: pointer;
}
#sub-menu {
position: absolute;
font-size: 32px;
font-weight: lighter;
color: #000;
border: solid 1px #ccc;
padding: 15px;
border-radius: 10px;
}
.move-enter-active,
.move-leave-active {
transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
</style>
The native transition property is not used because v-if is not supported, so the vue's transition component must be combined.
where cubic-bezier (0.175, 0.885, 0.32, 1.275); Is the key to provide transition effect, you can see that the entire menu will have a buffer transition effect, visually more impactful.