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

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;
	}
}
相关推荐
search72 小时前
前端设计:CRG 3--CDC error
前端
治金的blog2 小时前
vben-admin和vite,ant-design-vue的结合的联系
前端·vscode
利刃大大3 小时前
【Vue】Vue2 和 Vue3 的区别
前端·javascript·vue.js
荔枝一杯酸牛奶4 小时前
HTML 表单与表格布局实战:两个经典作业案例详解
前端·html
Charlie_lll5 小时前
学习Three.js–纹理贴图(Texture)
前端·three.js
yuguo.im5 小时前
我开源了一个 GrapesJS 插件
前端·javascript·开源·grapesjs
安且惜5 小时前
带弹窗的页面--以表格形式展示
前端·javascript·vue.js
米奇妙妙wuu5 小时前
css实现文字和边框同样的渐变色效果
css·html·css3
GISer_Jing6 小时前
AI驱动营销:业务技术栈实战(From AIGC,待总结)
前端·人工智能·aigc·reactjs
GIS之路8 小时前
GDAL 实现影像裁剪
前端·python·arcgis·信息可视化