2021-05-21

本文介绍了JavaScript新手在学习setInterval和clearInterval时遇到的问题,即clearInterval无法停止元素的移动。代码示例中展示了如何创建一个红色DIV的循环移动效果,并尝试通过stop()函数调用clearInterval来暂停移动,但效果不理想。问题可能在于clearInterval的使用时机不正确。
摘要由CSDN通过智能技术生成

js自学小白,最近学习到 setinterval() 和 clearinterval()方法。很好奇我的clearinterval()为啥不能够暂停它的转动。🙂;;;;

<!DOCTYPE> 
<html> 
<head> 
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<style>
		body{
			margin:0px;
			padding:0px;
			}
		.rltvC{
			height:800px;
			width:800px;
			position:relative;
			}
		.abslC{
			height:100px;
			width:100px;
			background-color:red;
			position:absolute;
			}
		.abslC1{
			height:80px;
			width:80px;
			background-color:white;
			position:absolute;
			left:350px;
			top:350px;
			}
		.abslC1 > button{
			font-size:19px;
		}
	</style>
</head> 
<body>
	<div id="rltv" class="rltvC">
		<div id="abslC" class="abslC">
		</div>
	</div>
	<div class="abslC1">
		<button type="button" onclick="moveleft()">转动这个红色的DIV</button>
		<button type="button" onclick="stop()">停止这个红色的DIV</button>
	</div>
</body> 
<script>
function moveleft(){
	var a = document.getElementById('abslC');
	var pos = 0;
	var pos2 = 0;
	var pos3 = 700;
	var pos4 = 700;
	var id = setInterval(frame,0.1);
	function frame(){
		if(pos == 701){
			clearInterval
		}else{
			if(pos < 700){
				pos++;
				a.style.left = pos + "px";
			}else{
				if(pos2 < 700){
					pos2++;
					a.style.top = pos2 + "px";
				}else{
					if(pos3 > 0){
						pos3--;
						a.style.left = pos3 + "px";
					}else{
						if(pos4 > 0){
							pos4--;
							a.style.top = pos4 + "px";
						}else{
							pos = 0;
							pos2 = 0;
							pos3 = 700;
							pos4 = 700;
						}
					}
				}
			}
		}
	}
}
function stop(){
	clearInterval(id);
}
</script>
</html> 

现在比较晚了,自己先记录一下,之后再找问题。如果有前辈可以提醒一下也万分感谢。   /(ㄒoㄒ)/~~

2021-03-26 20:54:33,596 - Model - INFO - Epoch 1 (1/200): 2021-03-26 20:57:40,380 - Model - INFO - Train Instance Accuracy: 0.571037 2021-03-26 20:58:16,623 - Model - INFO - Test Instance Accuracy: 0.718528, Class Accuracy: 0.627357 2021-03-26 20:58:16,623 - Model - INFO - Best Instance Accuracy: 0.718528, Class Accuracy: 0.627357 2021-03-26 20:58:16,623 - Model - INFO - Save model... 2021-03-26 20:58:16,623 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 2021-03-26 20:58:16,698 - Model - INFO - Epoch 2 (2/200): 2021-03-26 21:01:26,685 - Model - INFO - Train Instance Accuracy: 0.727947 2021-03-26 21:02:03,642 - Model - INFO - Test Instance Accuracy: 0.790858, Class Accuracy: 0.702316 2021-03-26 21:02:03,642 - Model - INFO - Best Instance Accuracy: 0.790858, Class Accuracy: 0.702316 2021-03-26 21:02:03,642 - Model - INFO - Save model... 2021-03-26 21:02:03,643 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 2021-03-26 21:02:03,746 - Model - INFO - Epoch 3 (3/200): 2021-03-26 21:05:15,349 - Model - INFO - Train Instance Accuracy: 0.781606 2021-03-26 21:05:51,538 - Model - INFO - Test Instance Accuracy: 0.803641, Class Accuracy: 0.738575 2021-03-26 21:05:51,538 - Model - INFO - Best Instance Accuracy: 0.803641, Class Accuracy: 0.738575 2021-03-26 21:05:51,539 - Model - INFO - Save model... 2021-03-26 21:05:51,539 - Model - INFO - Saving at log/classification/pointnet2_msg_normals/checkpoints/best_model.pth 我有类似于这样的一段txt文件,请你帮我写一段代码来可视化这些训练结果
02-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值