直线围绕中心点旋转(类似时钟)

javascript 复制代码
<view class="circleBoxSecond">
	<view class="circleBox">
		<div id="clock">
			<div class="hand second-hand"></div>
		</div>
	</view>
</view>
javascript 复制代码
onLoad() {		
	setTimeout(() => {
		this.secondHand = document.querySelector('.second-hand');
	}, 500)
	},
onShow() {
	setTimeout(() => {
		this.intervalId = setInterval(this.setDate, 500); // 每1000毫秒调用一次yourMethod方法
	}, 1000)
},
onHide() {
	// 页面隐藏时清除定时器
	clearInterval(this.intervalId);
},
javascript 复制代码
setDate() {
	const now = new Date();
	const seconds = now.getSeconds();
	const secondsDegrees = ((seconds / 60) * 360) + 90;
	this.secondHand.style.transform = `rotate(${secondsDegrees}deg)`;
},
javascript 复制代码
//style
.circleBoxSecond {
		width: 280rpx;
		height: 280rpx;
		border-radius: 50%;
		border: 1px solid green;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #f2f9f3;
	}

.circleBox {
	// margin: 20rpx 0;
	width: 200rpx;
	height: 200rpx;
	border-radius: 50%;
	border: 1px solid green;
	display: flex;
	justify-content: center;
	align-items: center;
	background-color: #ebf5ec;

	#clock {
		width: 120rpx;
		height: 120rpx;
		border: 1px solid green;
		border-radius: 50%;
		position: relative;
		background-color: #fff;
	}

	.hand {
		width: 50%;
		height: 1px;
		background-color: green;
		position: absolute;
		top: 50%;
		transform-origin: right center;
		transform: rotate(90deg);
	}

	.second-hand {
		height: 2rpx;
		background-color: green;
	}
}
相关推荐
WEI_Gaot1 分钟前
TS 为什么使用ts 和 创建ts的环境
前端·typescript
WEI_Gaot2 分钟前
TS 的类型注解大全
前端·typescript
i_am_a_div_日积月累_25 分钟前
前端路由缓存实现
前端·javascript·vue.js
咪库咪库咪43 分钟前
异步js和http请求
前端
厨猿加加44 分钟前
FlatList 在 React Native 的最佳实践
前端·react native
用户28800074867444 分钟前
前端连接VNC(无需后端)的完整教程
前端
郝某人一生平安1 小时前
前端 Word 模板参入特定数据 并且下载
前端·vue.js
jaffees1 小时前
自定义多级联动选择器(uni-app)
前端
_一条咸鱼_1 小时前
深入剖析 Vue 过滤器模块(十三)
前端·javascript·面试
独立开阀者_FwtCoder1 小时前
一口气讲清楚:LLM、MCP、EMB
前端·javascript·人工智能