Mas*_*olu 5 javascript css css-animations reactjs react-native
我想为我的按钮和图像创建发光动画。我想知道是否有一个反应原生动画可以用来实现这种发光效果。我有这种 css 样式,但我认为它不适用于本机反应。关于如何在react-native或react.js中对按钮或图像执行此操作有什么想法吗?
.glow {
font-size: 80px;
color: #fff;
text-align: center;
-webkit-animation: glow 1s ease-in-out infinite alternate;
-moz-animation: glow 1s ease-in-out infinite alternate;
animation: glow 1s ease-in-out infinite alternate;
}
@-webkit-keyframes glow {
from {
text-shadow: 0 0 10px #fff, 0 0 20px #fff, 0 0 30px #e60073, 0 0 40px #e60073, 0 0 50px #e60073, 0 0 60px #e60073, 0 0 70px #e60073;
}
to {
text-shadow: 0 0 20px #fff, 0 0 30px #ff4da6, 0 0 40px #ff4da6, 0 0 50px #ff4da6, 0 0 60px #ff4da6, 0 0 70px #ff4da6, 0 0 80px #ff4da6;
}
}
Run Code Online (Sandbox Code Playgroud)
我认为在React Native中使用关键帧不可用,所以我实现了自己的解决方案:
this.state = {
isBlinking: false
};
this.blinkingInterval = false;
componentWillUnmount() {
clearInterval(this.blinkingInterval);
this.blinkingInterval = false;
}
componentDidMount() {
if (!this.blinkingInterval) {
this.blinkingInterval = setInterval(() => {
this.setState({
isBlinking: !this.state.isBlinking
});
}, 800);
}
}
Run Code Online (Sandbox Code Playgroud)
在渲染中:
<Text style={this.state.isBlinking && styles.textGlowing}>Hello World</Text>
Run Code Online (Sandbox Code Playgroud)
在CSS文件中:
textGlowing: {
textShadowColor: 'rgba(0, 0, 0, 0.75)',
textShadowOffset: {width: -1, height: 1},
textShadowRadius: 15
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10585 次 |
| 最近记录: |