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>
相关推荐
sean1 分钟前
开发一个自己的 claude code
前端·后端·ai编程
用户21411832636025 分钟前
dify案例分享-用 Dify 一键生成教学动画 HTML!AI 助力,3 分钟搞定专业级课件
前端
学会煎墙2 小时前
使用uniapp——实现微信小程序的拖拽排序(vue3+ts)
微信小程序·uni-app·vue·ts
太过平凡的小蚂蚁2 小时前
Kotlin 协程中常见的异步返回与控制方式(速览)
开发语言·前端·kotlin
淡淡蓝蓝3 小时前
uni-app小程序往飞书多维表格写入内容(包含图片)
小程序·uni-app·飞书
咖啡の猫3 小时前
Vue初始化脚手架
前端·javascript·vue.js
晨枫阳3 小时前
uniapp兼容问题处理总结
前端·vue.js·uni-app
iOS阿玮4 小时前
苹果 Swift 安卓SDK上线,用一套 Swift 代码开发安卓 App 成为可能!
uni-app·app·apple
2501_915921434 小时前
iOS混淆与IPA加固全流程(iOS混淆 IPA加固 Ipa Guard实战)
android·ios·小程序·https·uni-app·iphone·webview
liusheng4 小时前
腾讯地图 SDK 接入到 uniapp 的多端解决方案
前端·uni-app