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>
相关推荐
风止何安啊17 分钟前
收到字节的短信:Trae SOLO上线了?尝尝鲜,浅浅做个音乐播放器
前端·html·trae
抱琴_24 分钟前
大屏性能优化终极方案:请求合并+智能缓存双剑合璧
前端·javascript
用户4639897543225 分钟前
Harmony os——长时任务(Continuous Task,ArkTS)
前端
fruge25 分钟前
低版本浏览器兼容方案:IE11 适配 ES6 语法与 CSS 新特性
前端·css·es6
颜酱43 分钟前
开发工具链-构建、测试、代码质量校验常用包的比较
前端·javascript·node.js
颜酱1 小时前
package.json 配置指南
前端·javascript·node.js
todoitbo1 小时前
基于 DevUI MateChat 搭建前端编程学习智能助手:从痛点到解决方案
前端·学习·ai·状态模式·devui·matechat
oden2 小时前
SEO听不懂?看完这篇你明天就能优化网站了
前端
IT_陈寒2 小时前
React性能优化:这5个Hooks技巧让我减少了40%的重新渲染
前端·人工智能·后端
Sunhen_Qiletian2 小时前
《Python开发之语言基础》第六集:操作文件
前端·数据库·python