目录
react弹窗动效组件
封装背景
使用效果
小程序中使用css3动画会有卡顿问题,决定封装一个组件来解决这个问题,然后发现 css中 will-change 可以有效的解决动画卡顿问题,所以做了如下封装。
弹窗底部弹起效果
弹窗中间弹起效果
使用方法(只需嵌套到最外层,就可以实现动效,用法简单)
import ModalAnimate from '../ModalAnimate/ModalAnimate';<ModalAnimate>弹窗内容</ModalAnimate>
组件属性
属性值 | 类型 | 描述 | 默认值 |
type | string | 弹窗从哪个地方弹起(bottom/center) | center |
组件源码
ModalAnimate.jsx
import React from "react"
import './ModalAnimate.less'class ModalAnimate extends React.Component {constructor(props) {super(props)this.state = {isActive: false}}componentDidMount() {setTimeout(() => {this.setState({isActive: true})}, 50)}render() {const { type = 'center' } = this.propsconst cls = ['modalAnimate']if (type === 'bottom') cls.push('modalBottomIn')if (type === 'center') cls.push('modalZoomIn')if (this.state.isActive) cls.push('active')return (<div className={cls.join(' ')}>{this.props.children}</div>)}
}export default ModalAnimate
ModalAnimate.less
.modalAnimate {width: 100%;height: 100%;transition: all 0.3s ease;will-change: contents;opacity: 1;
}.modalZoomIn {transform: scale3d(0.1, 0.1, 1);&.active {transform: scale3d(1, 1, 1);}
}.modalBottomIn {transform: translate3d(0, 100%, 0);&.active {transform: translate3d(0, 0, 0);}
}
新增活动修改动效可以参考上面的部分。兼容小程序等兼容性良好
本文发布于:2024-02-01 02:47:58,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170672687833328.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |