用js做一个可显示可拖动的缩放数值条

说明:可拖拽数值条进行值的变化;单击缩放按钮则+1(可设定);长按则持续+5(可设定);点击恢复则返回到最初值(可设定);值的范围为0~100(可设定),超出则按0/100作为最终值;zoom.value内存放着值,可进行传参,应用于你的程序。

 

用js制作缩放拖动条

 controlCamera.js

/*用于云台控制界面
 * 主要功能有:	
 * 				传递方向控制参数、传递缩放参数(值为zoom.value内的值)
 * 				缩放点击效果(点击加1,长按连续加5)
 * 
 * */
				var oldvalue='';//为存放当前操作的id
		        let time="";//延时时间初始化
		        let lock=true;//锁,防止单击与长按相互冲突
				var minvalue=0;//设定范围最小值
				var maxvalue=100;//设定范围最大值
				var inivalue=50;//设定范围最初值
				var short=1;//短按增(减)量
				var long=5;//长按增(减)量

//减小数值,单击减1
			    function minus(){
			    	if(lock){
				    	var num=document.getElementById("zoom").value;
				    	if(num==minvalue){
				    		num=minvalue;
				    	}
				    	else{
				    		num=Number(num)-short;
				    	}
						document.getElementById("zoom").value=num;
						document.getElementById("showZoom").innerHTML=num;
			    	}
			    }
//减小数值,长按1s持续减5		    
				function downMinus(){
		            time=setInterval(()=>{
		            	lock=false;
				    	var num=document.getElementById("zoom").value;
				    	num=Number(num)-long;
				    	if(num<minvalue){
				    		num=minvalue;
				    	}
						document.getElementById("zoom").value=num;
						document.getElementById("showZoom").innerHTML=num;
		             },1000)
 
		        }			    
//恢复默认值			    
			    function repeat(){
			    	var num=inivalue;
					document.getElementById("zoom").value=num;
					document.getElementById("showZoom").innerHTML=num;
			    }
//增加数值,单击加1		
   			    function plus(){
		    		if(lock){
				    	var num=document.getElementById("zoom").value;
				    	if(num==maxvalue){
				    		num=maxvalue;
				    	}
				    	else{
				    		num=Number(num)+short;
				    	}
						document.getElementById("zoom").value=num;
						document.getElementById("showZoom").innerHTML=num;
			   	 	}
			    }
//增加数值,长按1s持续加5			    	    
				function downPlus(){
		            time=setInterval(()=>{
		            	lock=false;
				    	var num=document.getElementById("zoom").value;
				    	num=Number(num)+long;
				    	if(num>maxvalue){
				    		num=maxvalue;
				    	}
						document.getElementById("zoom").value=num;
						document.getElementById("showZoom").innerHTML=num;
		             },1000)
 
		        }
//松开鼠标计时器清零,重新计时
		        function up(){
		        
		            clearTimeout(time);
		        
                    setTimeout(()=>{
               			lock=true;
           			})
		        }
//将缩放值显示
		        function range(){
		        	document.getElementById("showZoom").innerHTML=document.getElementById("zoom").value;
		        }		        
//点击事件
			    document.getElementById("repeatbtn").addEventListener("click", function(){repeat()});

 可在此处进行数值范围的设定:

 id值图示:

 

 

main.html全部内容如下:

<!DOCTYPE html>
<html >
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<!--360浏览器优先以webkit内核解析-->
		<title>main</title>
		<link href="./css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
		<link href="./css/font-awesome.min.css" th:href="@{/css/font-awesome.min.css}" rel="stylesheet"/>
		<link href="./css/style.min.css" th:href="@{/css/style.min.css}" rel="stylesheet"/>
		<link href="./css/style.min.css" th:href="@{/css/ckplayer.css}" rel="stylesheet"/>

		<style type="text/css">
			.setpadding{
			padding-top:0px;
			padding-bottom:0px;
			padding-left:3px;
			padding-right:2px;

			}
			.clearmargin{
			margin-top:0px;
			margin-bottom:0px;
			margin-left:0px;
			margin-right:0px;

			}

		</style>
	</head>
	<body>
		 <div class="col-md-4 clearmargin setpadding" style="padding-top:25px">
			<form >
				<div class="col-md-3 clearmargin setpadding" style="width:25%">
					<button id="minusbtn" onmousedown="downMinus()" onmouseup="up()" onclick="minus()" class="btn btn-w-m btn-default" style="min-width:43px;font-size:20px;width:40px;height:40px;border-radius:100% 10% 10% 100%;padding-top:0px;margin-top:3px!important" type="button"><i class="fa fa-search-minus" style="padding-top:10px"></i></button>		         
				</div>
				<div class="col-md-2 " style="padding:0">
					<div id="showZoom" style="padding-top:10px;font-size:20px;" >50</div>
				</div>
				<div class="col-md-1 " style="padding:0;font-size:20px;margin-top:10px">%</div>
				<div class="col-md-3 clearmargin setpadding" style="width:25%">
					<button id="plusbtn" onmousedown="downPlus()" onmouseup="up()" onclick="plus()" class="btn btn-w-m btn-default" style="min-width:43px;font-size:20px;width:40px;height:40px;border-radius:10% 100% 100% 10%;padding-top:0px;margin-top:3px!important" type="button"><i class="fa fa-search-plus" style="padding-top:10px"></i></button>		         
				</div>
				<div class="col-md-3 clearmargin setpadding" style="width:25%">
					<button id="repeatbtn" class="btn btn-w-m btn-default" style="min-width:43px;font-size:20px;width:40px;height:40px;border-radius:100%;padding-top:0px;margin-top:3px!important" type="button"><i class="fa fa-repeat" style="padding-top:10px"></i></button>		         
				</div>
				<div class="col-md-12 clearmargin setpadding" style="margin-top:10px">
					<input type="range" id="zoom"  value="50" oninput="range()" >
				</div>
			</form>
		 </div>
		 <!--    云台控制功能 (上下左右及缩放)-->    
		<script src="./js/controlCamera.js"></script> 
	</body>
</html>

我的项目目录:

 

项目代码(百度云资源):

链接:https://pan.baidu.com/s/1QIVypWhdFMEl2i3XA3W5gw?pwd=y4q5 
提取码:y4q5 
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值