警报函数-Javascript作为等待函数
我的应用程序是aps.net MVC,我使用ajax加载多个图像,通过获取鼠标Y位置,它可以工作,但是如果我移动鼠标超过一个像素,例如100,它会一次加载所有图像!为了测试脚本,我添加了警报,当用户单击ok时,图像会按预期的方式前进。我试过设置间隔和超时,但都不起作用。这是我的密码:警报函数-Javascript作为等待函数,javascript,asp.net-mvc,alert,setinterval,Javascript,Asp.net Mvc,Alert,Setinterval,我的应用程序是aps.net MVC,我使用ajax加载多个图像,通过获取鼠标Y位置,它可以工作,但是如果我移动鼠标超过一个像素,例如100,它会一次加载所有图像!为了测试脚本,我添加了警报,当用户单击ok时,图像会按预期的方式前进。我试过设置间隔和超时,但都不起作用。这是我的密码: $("#container2").bind('mousemove', function (e) { lastX = e.pageX - position.x; lastY = e
$("#container2").bind('mousemove', function (e) {
lastX = e.pageX - position.x;
lastY = e.pageY - position.y;
coordinate = "x=" + lastX + ", y=" + lastY;
$('#pValue').val(coordinate);
$('#lastX').val(lastX);
$('#lastY').val(lastY);
waitStep = lastY >= 0 ? 1 : -1;
waitInc = waitStep;
waitCounter = lastY;
for (var n = 0; n < Math.abs(lastY); n += 1) {
// imageSequence[n] = new Image();
dicom1.src = '/Home/GenerateImage?' + $.param({
pX: pointXF,
pY: pointYF,
pZ: waitInc * sThickness
});
waitInc = waitInc + waitStep;
alert(waitInc);
}
$(“#container2”).bind('mousemove',函数(e){
lastX=e.pageX-位置x;
lastY=e.pageY-位置.y;
坐标=“x=”+lastX+”,y=“+lastY;
$('#pValue').val(坐标);
$('#lastX').val(lastX);
$('lastY').val(lastY);
waitStep=lastY>=0?1:-1;
waitInc=waitStep;
waitCounter=拉斯蒂;
对于(变量n=0;n
非常感谢您的建议,提前谢谢。试试:
var speed = 15;
var timeout = 0;
$("#container2").bind('mousemove', function (e) {
if (!timeout) {
timeout = setTimeout(function(){
timeout = 0;
lastX = e.pageX - position.x;
lastY = e.pageY - position.y;
coordinate = "x=" + lastX + ", y=" + lastY;
$('#pValue').val(coordinate);
$('#lastX').val(lastX);
$('#lastY').val(lastY);
waitStep = lastY >= 0 ? 1 : -1;
waitInc = waitStep;
waitCounter = lastY;
for (var n = 0; n < Math.abs(lastY); n += 1) {
// imageSequence[n] = new Image();
dicom1.src = '/Home/GenerateImage?' + $.param({
pX: pointXF,
pY: pointYF,
pZ: waitInc * sThickness
});
waitInc = waitInc + waitStep;
alert(waitInc);
}
}, speed);
}
});
var速度=15;
var超时=0;
$(“#container2”).bind('mousemove',函数(e){
如果(!超时){
timeout=setTimeout(函数(){
超时=0;
lastX=e.pageX-位置x;
lastY=e.pageY-位置.y;
坐标=“x=”+lastX+”,y=“+lastY;
$('#pValue').val(坐标);
$('#lastX').val(lastX);
$('lastY').val(lastY);
waitStep=lastY>=0?1:-1;
waitInc=waitStep;
waitCounter=拉斯蒂;
对于(变量n=0;n
要在15日执行一次代码,您可以尝试:
var speed = 0;
$("#container2").bind('mousemove', function (e) {
++speed;
if (speed % 15 == 0) {
lastX = e.pageX - position.x;
lastY = e.pageY - position.y;
coordinate = "x=" + lastX + ", y=" + lastY;
$('#pValue').val(coordinate);
$('#lastX').val(lastX);
$('#lastY').val(lastY);
waitStep = lastY >= 0 ? 1 : -1;
waitInc = waitStep;
waitCounter = lastY;
for (var n = 0; n < Math.abs(lastY); n += 1) {
// imageSequence[n] = new Image();
dicom1.src = '/Home/GenerateImage?' + $.param({
pX: pointXF,
pY: pointYF,
pZ: waitInc * sThickness
});
waitInc = waitInc + waitStep;
alert(waitInc);
}
}
});
var速度=0;
$(“#container2”).bind('mousemove',函数(e){
++速度;
如果(速度%15==0){
lastX=e.pageX-位置x;
lastY=e.pageY-位置.y;
坐标=“x=”+lastX+”,y=“+lastY;
$('#pValue').val(坐标);
$('#lastX').val(lastX);
$('lastY').val(lastY);
waitStep=lastY>=0?1:-1;
waitInc=waitStep;
waitCounter=拉斯蒂;
对于(变量n=0;n
您的代码明确迭代并加载Y方向上移动的每个像素的图像。如果您不想这样做,为什么要这样编码?这是一个3D DICOM图像,我通过在画布上上上下移动鼠标来更改Z轴;它可以工作,但跳到最后一个位置,而不显示其他层。再次感谢,但是它不起作用。我正在尝试用等待函数替换alter。