如题:如果使用onmousedown和onmouseup来决定指令发送和指令停止会不会有问题?
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>两个事件之间的时间差</title> <script> var last=0; function myFunction(elmnt,event,clr){ var d = new Date(); var moveIn = d.getTime(); console.info(event+" "+moveIn+" cost:"+(last>0?moveIn-last:0)); elmnt.style.color=clr; last=moveIn; } </script> </head> <body> <a onmousedown="myFunction(this,'onmousedown','red')" onmouseup="myFunction(this,'onmouseup','green')"> 单击文本改变颜色。触发一个带参数函数,当鼠标按钮被按下,,当释放鼠标按钮,再一次触发其他参数函数 </a> </body> </html>
在OCX控件调用上遇到发指令的问题,在一个单独的html上执行没有问题,放到项目里面使用requireJs调用OCX接口播放和录像检索也都OK,唯独云台控制不行,从上面看down和up之间的间隔时间基本在100毫秒左右。
云台指令:onmousedown下发,onmouseup结束,由于不知道视频SDK服务商的指令实现逻辑为什么要这样处理,所以这个是最大的问题。
关键点:requireJS 是封装类,而OCX是IE的插件对象,指令走包装过程由于间隔时间太短不能成功发送。
/* $("#yt_direction_top").on('mousedown',function(){ upstart(); }); */ function upstart(){ require(['videoStart'],function(video){ video.upstart(); }); } /* $("#yt_direction_top").on('mouseup',function(){ upstop(); }); */ function upstop(){ require(['videoStart'],function(video){ video.upstop(); }); } /* $("#yt_direction_bottom").on('mousedown',function(){ downstart(); }); */ function downstart(){ require(['videoStart'],function(video){ video.downstart(); }); } /* $("#yt_direction_bottom").on('mouseup',function(){ downstop(); }); */ function downstop(){ require(['videoStart'],function(video){ video.downstop(); }); } /* $("#yt_direction_left").on('mousedown',function(){ leftstart(); }); */ function leftstart(){ require(['videoStart'],function(video){ video.leftstart(); }); } /* $("#yt_direction_left").on('mouseup',function(){ leftstop(); }); */ function leftstop(){ require(['videoStart'],function(video){ video.leftstop(); }); } /* $("#yt_direction_right").on('mousedown',function(){ rightstart(); }); */ function rightstart(){ require(['videoStart'],function(video){ video.rightstart(); }); } /* $("#yt_direction_right").on('mouseup',function(){ rightstop(); }); */ function rightstop(){ require(['videoStart'],function(video){ video.rightstop(); }); } /* $("#yt_zoom_add").on('mousedown',function(){ ZOOMstart(); }); */ function ZOOMstart(){ require(['videoStart'],function(video){ video.ZOOMstart(); }); } /* $("#yt_zoom_add").on('mouseup',function(){ ZOOMstop(); }); */ function ZOOMstop(){ require(['videoStart'],function(video){ video.ZOOMstop(); }); } /* $("#yt_zoom_reduce").on('mousedown',function(){ REDUCEZOOMstart(); }); */ function REDUCEZOOMstart(){ require(['videoStart'],function(video){ video.REDUCEZOOMstart(); }); } /* $("#yt_zoom_reduce").on('mouseup',function(){ REDUCEZOOMstop(); }); */ function REDUCEZOOMstop(){ require(['videoStart'],function(video){ video.REDUCEZOOMstop(); }); } /* $("#yt_focus_add").on('mousedown',function(){ FOCUSstart(); }); */ function FOCUSstart(){ require(['videoStart'],function(video){ video.FOCUSstart(); }); } /* $("#yt_focus_add").on('mouseup',function(){ FOCUSstop(); }); */ function FOCUSstop(){ require(['videoStart'],function(video){ video.FOCUSstop(); }); } /* $("#yt_focus_reduce").on('mousedown',function(){ REDUCEFOCUSstart(); }); */ function REDUCEFOCUSstart(){ require(['videoStart'],function(video){ video.REDUCEFOCUSstart(); }); } /* $("#yt_focus_reduce").on('mouseup',function(){ REDUCEFOCUSstop(); }); */ function REDUCEFOCUSstop(){ require(['videoStart'],function(video){ video.REDUCEFOCUSstop(); }); } /* $("#yt_aperture_add").on('mousedown',function(){ APERTUREstart(); }); */ function APERTUREstart(){ require(['videoStart'],function(video){ video.APERTUREstart(); }); } /* $("#yt_aperture_add").on('mouseup',function(){ APERTUREstop(); }); */ function APERTUREstop(){ require(['videoStart'],function(video){ video.APERTUREstop(); }); } /* $("#yt_aperture_reduce").on('mousedown',function(){ REDUCEAPERTUREstart(); }); */ function REDUCEAPERTUREstart(){ require(['videoStart'],function(video){ video.REDUCEAPERTUREstart(); }); } /* $("#yt_aperture_reduce").on('mouseup',function(){ REDUCEAPERTUREstop(); }); */ function REDUCEAPERTUREstop(){ require(['videoStart'],function(video){ video.REDUCEAPERTUREstop(); }); }
不封装的直接是可以的:
function upstart() { //g_CurChannelID //第二个参数 1 上 1下 2 左 3 右 4 var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 1, 6, 0); } function upstop() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 1, 6, 1); } function downstart() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 1, 6, 0); } function downstop() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 1, 6, 1); } function leftstart() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 2, 6, 0); } function leftstop() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 2, 6, 1); } function rightstart() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 3, 6, 0); } function rightstop() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 3, 6, 1); } function ZOOMstart() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 8, 6, 0); } function ZOOMstop() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 8, 6, 1); } function REDUCEZOOMEstart() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 11, 6, 0); } function REDUCEZOOMstop() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 11, 6, 1); } function FOCUSstart() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 9, 6, 0); } function FOCUSstop() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 9, 6, 1); } function REDUCEFOCUSEstart() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 12, 6, 0); } function REDUCEFOCUSstop() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 12, 6, 1); } function APERTUREstart() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 10, 6, 0); } function APERTUREstop() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 10, 6, 1); } function REDUCEAPERTUREstart() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 13, 6, 0); } function REDUCEAPERTUREstop() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.PTZControl(g_CurChannelID, 13, 6, 1); } function startTalk() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.TalkControl(g_CurChannelID, 0); } function stopTalk() { var g_CurChannelID = mini.get("CHANNEL_LIST").getValue(); var Res = ocx.TalkControl(g_CurChannelID, 1); }