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

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;
	}
}
相关推荐
web小白成长日记26 分钟前
企业级 Vue3 + Element Plus 主题定制架构:从“能用”到“好用”的进阶之路
前端·架构
APIshop1 小时前
Python 爬虫获取 item_get_web —— 淘宝商品 SKU、详情图、券后价全流程解析
前端·爬虫·python
风送雨1 小时前
FastMCP 2.0 服务端开发教学文档(下)
服务器·前端·网络·人工智能·python·ai
XTTX1101 小时前
Vue3+Cesium教程(36)--动态设置降雨效果
前端·javascript·vue.js
LYFlied2 小时前
WebGPU与浏览器边缘智能:开启去中心化AI新纪元
前端·人工智能·大模型·去中心化·区块链
Setsuna_F_Seiei2 小时前
2025 年度总结:人生重要阶段的一年
前端·程序员·年终总结
model20052 小时前
alibaba linux3 系统盘网站迁移数据盘
java·服务器·前端
han_3 小时前
从一道前端面试题,谈 JS 对象存储特点和运算符执行顺序
前端·javascript·面试
aPurpleBerry3 小时前
React 01 目录结构、tsx 语法
前端·react.js
jayaccc3 小时前
微前端架构实战全解析
前端·架构