uni-app:点击图片进行图片旋转(可自定义旋转次数)

效果

代码

html 复制代码
<template>
	<view>
		<view class="top_line">
			<view class="top_img">
				<image src="../../../static/bg/index.png" mode=""></image>
			</view>
			<view class="top_button">
				<image @tap="refresh" class="rotate-me" :class="{'rotated': isRotating}" :src="refresh_icon"></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				refresh_icon: getApp().globalData.icon + 'index/refresh.png', //图片
				isRotating: false, //旋转状态
			}
		},
		methods: {
			refresh() {
				this.isRotating = true;
				setTimeout(() => {
					this.isRotating = false;
				}, 2000); // 设置旋转时间,这里为2秒
			},
		},
		onLoad() {

		}
	}
</script>

<style lang="scss">
	//顶部样式
	.top_line {
		//顶部背景图
		.top_img {
			image {
				width: 100%;
				height: 300rpx;
			}
		}
		//顶部刷新按钮
		.top_button {
			position: absolute;
			top: 2%;
			right: 10%;
			
			.rotate-me {
				width: 50rpx;
				height: 50rpx;
				//元素变化过渡效果(transition:指定需要过渡的属性,1s过渡持续的时间;ease:指定过渡效果的缓动函数)
				transition: transform 1s ease;
			}

			.rotated {
				animation-name: rotate;//指定动画名称rotate,使用@keyframes rotate 
				animation-duration: 1s;//指定动画的持续时间
				animation-timing-function: ease;//ease 函数,表示动画开始缓慢,然后加速,最后减速到结束,使得旋转动画看起来更加平滑。
				animation-iteration-count: 2;//指定动画的重复次数

			}

			@keyframes rotate {
				0% {//初始状态
					transform: rotate(0deg);
				}

				100% {//完成时状态
					transform: rotate(360deg);
				}
			}
		}
	}
</style>
相关推荐
你好龙卷风!!!几秒前
uni-app 项目 iOS 个人免费真机调试打包全流程手册
ios·uni-app
@PHARAOH4 分钟前
WHAT - 替代 Express 和 Koa 的现代轻量版 Hono
前端·微服务·express·koa
掘金安东尼13 分钟前
低代码真的能替代前端吗?我看了 RollCode 的设计之后有点新想法
前端
IT_陈寒16 分钟前
JavaScript开发者必知的5个高效调试技巧,比console.log强10倍!
前端·人工智能·后端
亿元程序员20 分钟前
历时100天,亿元Cocos小游戏实战合集顺利完结!!!
前端
恋猫de小郭34 分钟前
Flutter Beta 版本引入 ScrollCacheExtent ,并修复长久存在的 shrinkWrap NaN 问题
android·前端·flutter
Liu.77435 分钟前
vscode前端实用插件
前端·vscode
HWL56791 小时前
使用CSS实现,带有动态浮动高亮效果的导航菜单
前端·css
GISer_Jing1 小时前
AI Agent技能Skills设计
前端·人工智能·aigc·状态模式
大漠_w3cpluscom1 小时前
使用 sibling-index() 和 if() 实现动态的 :nth-child()
前端