react实现汉堡_React动画切换(开关)按钮(汉堡菜单)组件

这篇博客介绍了如何使用React创建一个带有动画效果的汉堡菜单(开关)按钮。通过CSS样式实现线条的旋转动画,展示了在不同屏幕宽度下,汉堡菜单如何优雅地转换。代码示例中包含了组件的CSS样式和响应式设计。
摘要由CSDN通过智能技术生成

CSS

语言:

CSSSCSS

确定

.MenuToggle {

$line-color: #1f4772;

$line-height: 10%;

$animation-speed: 300ms;

$button-width: 100px;

$button-height: 80px;

position: relative;

width: $button-width;

height: $button-height;

background: transparent;

cursor: pointer;

-webkit-tap-highlight-color: rgba(0,0,0,0);

&:before,

&:after,

div {

position: absolute;

width: 100%;

height: $line-height;

background: $line-color;

transition: all $animation-speed;

}

&:before {

content: '';

top: 0;

}

&:after {

content: '';

bottom: 0;

}

div {

top: 50%;

transform: translateY(-50%);

transition: all $animation-speed / 2;

opacity: 1;

}

&--active {

&:before {

top: 50%;

transform: translateY(-50%) rotateZ(135deg);

}

&:after {

bottom: 50%;

transform: translateY(50%) rotateZ(45deg);

}

div {

opacity: 0;

}

}

}

// COMPONENT UNREALTED STYLES FOR DEMO

@import url('https://fonts.googleapis.com/css?family=Lato:100');

.scene {

position: absolute;

top: 0;

bottom: 0;

left: 0;

right: 0;

background: linear-gradient(-180deg, #261957 0%, #158b9b 100%);

}

.container {

position: absolute;

top: 50%;

left: 50%;

transform: translate(-50%, -50%);

text-align: center;

width: 370px;

}

.panel {

position: relative;

display: inline-block;

width: 170px;

height: 170px;

vertical-align: top;

text-align: left;

background: white;

> div {

position: absolute;

top: 50%;

left: 50%;

transform: translate(-50%, -50%);

}

}

.title {

display: inline-block;

width: 150px;

margin-left: 30px;

vertical-align: top;

font-size: 25px;

line-height: 32px;

font-family: 'Lato', sans-serif;

text-align: left;

color: white;

}

@media (max-width: 400px) {

.container {

width: 100%;

}

.title {

width: 80%;

margin: 30px 0 0 0;

text-align: center;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值