CSS3回转菜单是一种常见的动态菜单效果。它可以通过CSS3中的旋转属性实现菜单项的旋转展开和收起。
/* CSS样式代码 */
.container {
position: relative;
}
.menu-item {
position: absolute;
width: 50px;
height: 50px;
background-color: #3498db;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
cursor: pointer;
transition: all 0.3s ease-in-out;
}
.menu-item:hover {
transform: scale(1.2);
}
.menu-item.active {
transform: rotate(360deg) scale(1.2);
}
.menu-item:nth-of-type(1) {
bottom: 0;
left: 50%;
margin-left: -25px;
z-index: 4;
}
.menu-item:nth-of-type(2) {
bottom: 50%;
left: 0;
margin-bottom: -25px;
z-index: 3;
}
.menu-item:nth-of-type(3) {
bottom: 50%;
right: 0;
margin-bottom: -25px;
z-index: 3;
}
.menu-item:nth-of-type(4) {
top: 0;
left: 50%;
margin-left: -25px;
z-index: 2;
}
.menu-item:nth-of-type(5) {
top: 50%;
left: 0;
margin-top: -25px;
z-index: 1;
}
.menu-item:nth-of-type(6) {
top: 50%;
right: 0;
margin-top: -25px;
z-index: 1;
}
.sub-menu {
position: absolute;
width: 100px;
height: 100px;
background-color: #fff;
border-radius: 50%;
box-shadow: 0px 3px 3px rgba(0,0,0,0.2);
display: flex;
justify-content: center;
align-items: center;
opacity: 0;
pointer-events: none;
transition: all 0.3s ease-in-out;
}
.menu-item.active .sub-menu {
opacity: 1;
pointer-events: auto;
}
.sub-menu-item {
width: 30px;
height: 30px;
background-color: #ccc;
border-radius: 50%;
margin: 8px;
cursor: pointer;
transition: all 0.3s ease-in-out;
}
.sub-menu-item:hover {
transform: scale(1.2);
} 以上是一个CSS3回转菜单的基本样式代码。其中,菜单项通过设置position属性为absolute,以及通过nth-of-type选择器和不同的margin值分别从不同的位置展开。菜单项的hover效果通过transform属性实现。当用户点击一个菜单项时,它会添加一个active类名,同时展开对应的子菜单。
子菜单通过设置position属性为absolute和opacity属性为0隐藏。当它的父菜单项被点击时,它会通过设置opacity为1和pointer-events属性为auto展示出来。子菜单中的菜单项hover效果也通过transform属性实现。