0

这是当前代码(鼠标向下拖动以增加和减少框架):http: //jsfiddle.net/QHkfJ/

mousedown = false;
frame = 0;
mouse_x_last = 0;
$(document).ready
(
    function()
    {
        $("#load_overlay").mousedown
        (
            function()
            {
                mousedown = true;
            }
        );

        $("#load_overlay").mouseup
        (
            function()
            {
                mousedown = false;
            }
        );

        $("#load_overlay").mouseleave
        (
            function()
            {
                mousedown = false;
            }
        );

        $(window).mousemove
        (
            function(event)
            {
                mouse_x = event.pageX;

                if(mousedown == true)
                {
                    //if our current mouse position is greater than our last
                    if(mouse_x > mouse_x_last)
                    {
                        //if our frame is within the array
                        if(frame < 45)
                        {
                            //advance frame
                            frame++
                            //update debug frame#
                            $("#frame").html(frame);
                        }
                        else
                        {
                            //if our frame tries to exceed the array, reset to frame 0
                            frame = 0;
                        }
                        //set our last mouse position
                        mouse_x_last = mouse_x;
                    }

                    //if our current mouse position is lesser than our last
                    if(mouse_x < mouse_x_last)
                    {
                        //if our frame is within the array
                        if(frame > 0)
                        {
                            //decline frame
                            frame--
                            //update debug frame#
                            $("#frame").html(frame);
                        }
                        else
                        {
                            //if our frame tries to exceed the array, reset to set to 45
                            frame = 45;
                        }
                        //set our last mouse position
                        mouse_x_last = mouse_x;
                    }

                }

            }
        );
    }
);

我的问题是 ++ & -- 增加“框架”的速度。我想要一种方法来减慢这个速度。

非常感谢。

4

2 回答 2

1

而不是使用

$("#frame").html(frame);

你可以尝试除以一些东西:

$("#frame").html(Math.floor(frame / 5));

上面的代码将使它慢 5 倍。

小提琴

于 2013-06-13T13:07:51.070 回答
0

这是我对你的想法的看法。定义鼠标改变帧速率的宽度。相应地设置 WIDTH。

小提琴:http: //jsfiddle.net/QHkfJ/5/

$( function() {
    var mouseX,
        frames = 0,
        isMousedown = false,
        WIDTH = 200, // Number of pixels, increase to slow down
        FRAMES_MAX = 45,
        framesInit = frame,
        ratio      = FRAMES_MAX / WIDTH,
        $frame     = $("#frame");

    $( "#load_overlay" ).on ( "mousedown", function( event ) {
        isMousedown = true;
        mouseX      = event.pageX;
        framesInit  = parseInt( $frame.text(), 10 );
    }).on( "mouseup mouseleave", function() {
        isMousedown = false;
    });

    $( window ).on( "mousemove", function(event) {
        if( !isMousedown ) {
            return false;
        }
        var x    = event.pageX,
            dx   = x - mouseX,
            diff = Math.max( Math.min( dx, WIDTH), -WIDTH );
        frames = Math.min( Math.max( parseInt( ratio * diff, 10 ), 0 ), FRAMES_MAX );
        $frame.text( frames );
    });
});
于 2013-06-13T13:54:12.663 回答