DEVHIDE
  • Home (current)
  • About
  • Contact
  • Cookie
  • Home (current)
  • About
  • Contact
  • Cookie
  • Disclaimer
  • Privacy
  • TOS
Login Or Sign up

Closing modal with e.keypress

1.1k Views Asked by Matt At 17 November 2014 at 21:51 2025-12-20T17:30:54.149000

I have the following modal box:

<div class="modal-video" id="v-5417">
<div class="video-player">
                <video id="v-5417-tape" preload="none">
                    <source type="video/mp4" src="videos/anthem-od47.mp4">
                    <source type="video/webm" src="videos/anthem-od47.webm">
                </video>
                <div class="close-modal fade-control"></div>
</div>
</div>

and trying to use the following e.keyCode to close the modal:

        $(document).keydown(function (e) {
            if (e.keyCode == 27) {
                $(".modal-video").hide();
            }
        });

This is only hiding the video, but not closing the modal and killing the video. How can I completely close the modal and video together?

javascript jquery modal-dialog keycode
Original Q&A
2

There are 2 best solutions below

0
Marian Gibala Marian Gibala On 17 November 2014 at 22:32

jQuery .hide() just changes the CSS style to display:none, so your video is hided and still playing in the background. To fix that issue, you can stop playing the video by standard HTML5 pause() method.

If hiding $(".modal-video") doesn't work for you, then I assume you need to hide it's parent - but we have to see more your code to be sure about that.

$(document).keydown(function (e) {

    if (e.keyCode == 27) {

        var video = document.getElementById("v-5417-tape");
        video.pause()

        $(".modal-video").parent().hide();


    }
});

If you are using some kind of player template or plugin, and click on class "close-modal" hides the modal as you expect - then you can use jQuery .toggle() method to call click event on that element, when you press your key.

$(document).keydown(function (e) {

    if (e.keyCode == 27) {

        var video = document.getElementById("v-5417-tape");
        video.pause()

        $(".close-modal").toggle("click")


    }
});
0
Matt Matt On 18 November 2014 at 18:48

The active state has to be removed, and that disabled the popup.

$(document).keydown(function (e) {
        var video = document.getElementById("v-5417-tape");
        if (e.keyCode == 27) { 
        if(video.play){
            video.pause();
        }
            $(".modal-video").removeClass("active");

        }
    });

Related Questions in JAVASCRIPT

  • Angular Show All When No Filter Is Supplied
  • Why does a function show up as not defined
  • I count the time the user takes to solve my quiz using Javascript but I want the same time displayed on another page
  • Set "More" "Less" font size
  • Using pagination on a table in AngularJS
  • How to sort these using Javascript or Jquery Most effectively
  • how to fill out the table with next values in array with one button
  • State with different subviews
  • Ajax jQuery firing multiple time display event for the same result
  • Getting and passing MVC Model data to AngularJS controller
  • Disable variable in eval
  • javascript nested loops waiting for user input
  • .hover() seems to overwrite .click()
  • How to sort a multi-dimensional array by the second array in descending order?
  • How do I find the fonts that are not loading in a CORS situation ( MoovWeb )?

Related Questions in JQUERY

  • How to sort these using Javascript or Jquery Most effectively
  • Ajax jQuery firing multiple time display event for the same result
  • .hover() seems to overwrite .click()
  • Check for numeric value with optional commas javascript
  • Extending Highmaps Side Effect
  • Array appending after each onclick and loop in javascript
  • how can i append part of a table based on how many tr it has?
  • Play multiple audio files in a slider
  • Remove added set of rows
  • Access property of an object of type [Model] in JQuery
  • AJAX PHP - Reload div after submit
  • proengsoft/laravel-jsvalidation ReferenceError: jQuery is not defined
  • when a checkbox is checked how to display a different hidden element using javascript
  • Get jquery error Uncaught RangeError: Maximum call stack size exceeded
  • Removing only the closest thead on table filtering

Related Questions in MODAL-DIALOG

  • How to redirect to another popup on ASP.NET MVC
  • Angular is giving me an injection unresolved error, but my controller isn't asking for any injections
  • How to change MahApps.Metro dialog content template width?
  • AngularJs clear form in Modal and set it ng-invalid
  • Embedded qtip2 Modal in Fullcalendar + Google Calendar
  • pass href text to modal
  • Attempting to pop a modal window - Using Angular and Bootstrap
  • Modal not working in Ember.js app
  • Unknown provider: $modalInstanceProvider <- $modalInstance in Angularjs modal
  • How can a dialog become responsive while waiting for a call to DoModal() to return?
  • Multiple Modals on one page
  • Add modal window after submitting form
  • Bootstrap 3 - When modal hides it hides content
  • How can I open a modal from a modal template?
  • Modal Dialog in child WPF window

Related Questions in KEYCODE

  • What is the char represented by keycode (15) c#?
  • Is Shift the only key that can change the value of keyCode?
  • On click, press enter to textbox
  • How to print key character code in OSX?
  • Backslash key code is recognized as german umlaut
  • Convert char into KeyEvent on Android
  • Convert character in PHP to javascript event keycode
  • c# ascii to keycode?
  • c# textBox1.Text converting to KeyCode and send it to a chat program with SendMessage
  • Closing modal with e.keypress
  • List of hex keyboard scan codes and USB HID keyboard documentation
  • Problems with barcode reading using PreFilterMessage
  • How to combine key codes to work together in javascript
  • Delphi Key Code 17 in FormKeyDown
  • How can I format my character code to a string name

Trending Questions

  • UIImageView Frame Doesn't Reflect Constraints
  • Is it possible to use adb commands to click on a view by finding its ID?
  • How to create a new web character symbol recognizable by html/javascript?
  • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
  • Heap Gives Page Fault
  • Connect ffmpeg to Visual Studio 2008
  • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
  • How to avoid default initialization of objects in std::vector?
  • second argument of the command line arguments in a format other than char** argv or char* argv[]
  • How to improve efficiency of algorithm which generates next lexicographic permutation?
  • Navigating to the another actvity app getting crash in android
  • How to read the particular message format in android and store in sqlite database?
  • Resetting inventory status after order is cancelled
  • Efficiently compute powers of X in SSE/AVX
  • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

Popular # Hahtags

javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

Popular Questions

  • How do I undo the most recent local commits in Git?
  • How can I remove a specific item from an array in JavaScript?
  • How do I delete a Git branch locally and remotely?
  • Find all files containing a specific text (string) on Linux?
  • How do I revert a Git repository to a previous commit?
  • How do I create an HTML button that acts like a link?
  • How do I check out a remote Git branch?
  • How do I force "git pull" to overwrite local files?
  • How do I list all files of a directory?
  • How to check whether a string contains a substring in JavaScript?
  • How do I redirect to another webpage?
  • How can I iterate over rows in a Pandas DataFrame?
  • How do I convert a String to an int in Java?
  • Does Python have a string 'contains' substring method?
  • How do I check if a string contains a specific word?
.

Copyright © 2021 Jogjafile Inc.

  • Disclaimer
  • Privacy
  • TOS
  • Homegardensmart
  • Math
  • Aftereffectstemplates