css实现盒子缓慢展开效果,纯CSS3 创意菜单 盒子展开动画

CSS

语言:

CSSSCSS

确定

@import url(http://fonts.googleapis.com/css?family=Open+Sans:300,400|Dosis:200,300,400);

*, *:before, *:after {

-webkit-box-sizing: border-box;

-moz-box-sizing: border-box;

box-sizing: border-box; }

body {

padding: 20px 0;

background: #111; }

#tog {

margin: auto;

padding: 0;

display: block;

position: absolute;

top: 0;

right: 0;

bottom: 0;

left: 0;

width: 140px;

height: 140px;

background: #fafafa;

font-family: 'Dosis';

font-weight: 200;

font-size: 1.8em;

text-align: center;

line-height: 140px;

color: #111;

cursor: pointer;

-webkit-transition: all 0.25s;

-moz-transition: all 0.25s;

-ms-transition: all 0.25s;

-o-transition: all 0.25s;

transition: all 0.25s;

z-index: 125; }

#tog:hover {

background: #7a3fae;

color: #fafafa; }

#menu {

margin: auto;

padding: 0;

display: block;

position: absolute;

top: 0;

right: 0px;

bottom: 0;

left: 0;

width: 140px;

height: 140px;

background: red;

-webkit-transition: all 0.1s;

-moz-transition: all 0.1s;

-ms-transition: all 0.1s;

-o-transition: all 0.1s;

transition: all 0.1s;

z-index: 100; }

.button {

margin: 0;

padding: 0;

display: block;

position: absolute;

top: 0;

right: 0;

bottom: 0;

left: 0;

width: 140px;

height: 140px;

background: #f0f0f0;

font-family: 'Dosis';

font-weight: 200;

font-size: 1.8em;

text-align: center;

line-height: 140px;

color: #111;

cursor: pointer;

-webkit-transition: all 0.25s;

-moz-transition: all 0.25s;

-ms-transition: all 0.25s;

-o-transition: all 0.25s;

transition: all 0.25s; }

.button:hover {

background: none;

color: #fafafa; }

.button:active {

color: #7a3fae; }

#check {

display: none; }

#check:checked ~ #tog {

background: #111;

color: #fafafa; }

#check:checked ~ #menu .button:nth-child(1) {

top: -20px; }

#check:checked ~ #menu .button:nth-child(1):hover {

top: -140px; }

#check:checked ~ #menu .button:nth-child(2) {

left: 20px; }

#check:checked ~ #menu .button:nth-child(2):hover {

left: 140px; }

#check:checked ~ #menu .button:nth-child(3) {

top: 20px; }

#check:checked ~ #menu .button:nth-child(3):hover {

top: 140px; }

#check:checked ~ #menu .button:nth-child(4) {

left: -20px; }

#check:checked ~ #menu .button:nth-child(4):hover {

left: -140px; }

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现点击扇形展开效果菜单,需要使用CSS中的transform和transition属性。以下是一种实现方式: HTML结构: ```html <div class="menu"> <div class="item item1"></div> <div class="item item2"></div> <div class="item item3"></div> <div class="item item4"></div> <div class="item item5"></div> <div class="center"></div> </div> ``` CSS样式: ```css .menu { position: relative; width: 200px; height: 200px; } .item { position: absolute; width: 50px; height: 50px; background-color: #ccc; border-radius: 50%; transition: transform 0.5s ease; } .item1 { top: -25px; left: 75px; } .item2 { top: 35px; left: 35px; } .item3 { top: 75px; left: -25px; } .item4 { top: 35px; left: -85px; } .item5 { top: -25px; left: -45px; } .center { position: absolute; top: 50%; left: 50%; width: 20px; height: 20px; background-color: #333; border-radius: 50%; transform: translate(-50%, -50%); cursor: pointer; } ``` JavaScript代码: ```javascript var menu = document.querySelector('.menu'); var items = document.querySelectorAll('.item'); var center = document.querySelector('.center'); var isOpen = false; center.addEventListener('click', function() { if (isOpen) { // 关闭菜单 menu.classList.remove('open'); items.forEach(function(item, index) { item.style.transform = 'rotate(0deg)'; }); } else { // 打开菜单 menu.classList.add('open'); items.forEach(function(item, index) { item.style.transform = 'rotate(' + (index * 72) + 'deg)'; }); } isOpen = !isOpen; }); ``` 在上面的代码中,我们通过JavaScript监听中心圆的点击事件,并根据菜单是否打开来决定是展开还是收起菜单。当菜单打开时,我们给菜单容器添加open类名,并将每个菜单项按照一定角度旋转,从而形成扇形展开效果。当菜单关闭时,我们将open类名移除,并将每个菜单项旋转回初始状态。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值