admin管理员组

文章数量:1303536

I am using Lean Modal for a Modal on my web app.

Lean Modal Website: /

Its all working fine. I just want to add the event "Esc Button Click" which closes the modal. How can I do it? Please advise.

I am using Lean Modal for a Modal on my web app.

Lean Modal Website: http://leanmodal.finelysliced..au/

Its all working fine. I just want to add the event "Esc Button Click" which closes the modal. How can I do it? Please advise.

Share asked Sep 27, 2013 at 7:23 Pratik PoddarPratik Poddar 1,3453 gold badges18 silver badges36 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

Based on the demos on their homepage, you can close the modal by clicking outside it. You just need to trigger the same click event when ESC key is pressed. This ensures that the closing is actually done by the plugin itself and not by you.

$(document).keyup(function(ev){
    if(ev.keyCode == 27)
        $("#lean_overlay").trigger("click");
});

Do something like

$(window).bind('keyup',function(e){
    if(e.keyCode == 27)
        $('#signup,#lean_overlay').fadeOut();
})

For the example on demo page

<a href id="modal" tabindex="-1" >Click to open </a>

add tabindex="-1" if you are using jquery .

本文标签: javascriptModal (LeanModal) Close by Esc KeyStack Overflow