Search code examples
javascriptjquerybuttongifsimplemodal

Remove stop GIF animation function from ESC button


I want to remove stop GIF animation function from ESC button is it possible?

Please see this : http://jsfiddle.net/f8emy/

Press Upload then hit ESC once then press upload again and you'll notice the GIF animation stop moving.

Now i know you're gonna ask me why did i disable the SimpleModal internal ESC function:

escClose: false

and added another ESC function:

$(function() {
    $(document).on('keydown', function(e) {
        if (e.keyCode === 27) {
            $.modal.close();
        }
    });
});

is it because this way it will also cancel the page from loading instead of just closing the SimpleModal so that it will cancel the upload also.

What i want exactly is when you click upload the simplemodal will appear with the GIF and then if you pressed ESC it will close the simplemodal and cancel the uplaod (stop page from loading) then if you press upload again it will be the same with the GIF animation still playing inside the simplemodal. Thanks


Solution

  • This is job for everyone's favorite Super Hero:preventDeafult()-man!

    // Close SimpleModal & Cancel Page Loading (from uploading)
    $(function() {
        $(document).on('keydown', function(e) {
            if (e.keyCode === 27) {
                e.preventDefault(); //prevent browser from stopping animation
                $.modal.close();
            }
        });
    });
    

    Updated your jsFiddle.

    Firefox will stop gif animations when Esc is pressed; e.preventDefault() will prevent this action, and keep the party, erm...gif animation, going.