CSS 实现图片旋转和水波纹动画效果

CSS 实现图片旋转和水波纹动画效果

背景


通过 CSS 动画实现图片旋转和水波纹动画效果,并做成 Vue 组件,方便以后复用。

代码


<template>
	<view class="container">
		<view class="rotate-container">
			<view class="dot">
				<van-image :image-class="rotateActive" round width="150" height="150" :src="src">
				</van-image>
				<view :class="{pulse: rotate, p1: rotate}"></view>
				<view :class="{pulse: rotate, p2: rotate}"></view>
			</view>
			
		</view>
		<view class="info-container">
			<view class="song-name">{{songName}}</view>
			<view class="author-name">{{authorName}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'RotateImage',
		props: {
			rotate: {
				type: Boolean,
				default: true
			},
			src: {
				type: String,
				default: 'https://img.yzcdn.cn/vant/cat.jpeg'
			},
			songName: {
				type: String,
				default: '告白气球'
			},
			authorName: {
				type: String,
				default: '周杰伦'
			}
		},
		computed: {
			rotateActive() {
				return this.rotate ? 'rotate' : ''
			}
		},
		data() {
			return {

			}
		},
		methods: {

		}
	}
</script>

<style>
	.container {
		display: flex;
		flex-direction: column;
		align-items: center;
		position: relative;
	}

	.dot {
		position: relative;
	}

	/* --- 水波纹动画 start --- */
	.pulse {
		position: absolute;
		width: 150px;
		height: 150px;
		left: 0;
		top: 0;
		border: 3rpx solid #ffd213;
		border-radius: 50%;
		opacity: 0;
	}

	.p1 {
		animation: warn 2s ease-out infinite;
	}

	.p2 {
		animation: warn2 2s ease-out infinite;
	}

	@keyframes warn {
		0% {
			transform: scale(1.2);
			opacity: 0.0;
		}

		25% {
			transform: scale(1.2);
			opacity: 0.1;
		}

		50% {
			transform: scale(1.5);
			opacity: 0.3;
		}

		75% {
			transform: scale(1.8);
			opacity: 0.5;
		}

		100% {
			transform: scale(2);
			opacity: 0.0;
		}
	}

	@keyframes warn2 {
		0% {
			transform: scale(1.2);
			opacity: 0.0;
		}

		25% {
			transform: scale(1.2);
			opacity: 0.1;
		}

		50% {
			transform: scale(1.2);
			opacity: 0.3;
		}

		75% {
			transform: scale(1.5);
			opacity: 0.5;
		}

		100% {
			transform: scale(1.8);
			opacity: 0.0;
		}
	}
	/* --- 水波纹动画 end --- */

	/* --- 图片旋转动画 start --- */
	@-webkit-keyframes rotation {
		from {
			-webkit-transform: rotate(0deg);
		}

		to {
			-webkit-transform: rotate(360deg);
		}
	}

	/* 旋转 */
	.rotate {
		display: inline-block;
		-webkit-transform: rotate(360deg);
		animation: rotation 8s linear infinite;
		-moz-animation: rotation 8s linear infinite;
		-webkit-animation: rotation 8s linear infinite;
		-o-animation: rotation 8s linear infinite;
		animation-play-state: running;
	}

	/* 清除旋转 */
	.stop-rotate {
		-webkit-transform: rotate(0deg);
		animation: rotation 0s linear infinite;
		-moz-animation: rotation 0s linear infinite;
		-webkit-animation: rotation 0s linear infinite;
		-o-animation: rotation 0s linear infinite;
		animation-play-state: paused;
	}

	/* --- 图片旋转动画 end --- */
	
	.info-container {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-top: 1em;
	}
	
	.author-name {
		font-size: small;
		color: #999999;
	}
</style>

效果


在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值