0

我的应用程序是 aps.net MVC,我是否使用 ajax 加载多个图像,通过获取鼠标 Y 位置,它可以工作,但是如果我将鼠标移动超过一个像素,例如 100,它会一次加载所有图像!为了测试脚本,我添加了警报,当用户单击确定时,图像按预期前进。我尝试了 setInterval 和 Timeout,都没有奏效。这是我的代码:

 $("#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);


        }

非常感谢您的建议,在此先感谢。

4

2 回答 2

1

尝试 :

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);
    }
});
于 2013-04-22T21:00:06.103 回答
0

要在 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);
           }
    }
});
于 2013-04-23T12:27:47.637 回答