Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 1 of 1
  1. #1
    Member
    Join Date
    Jun 2014
    Posts
    47
    Member #
    39433
    Liked
    1 times

    Stop Video on Modal Close

    I have several modals, each with a different iframe with a different embedded youtube video.

    When someone closes out of the modal (either by clicking away, hitting ESC or closing it), I would like the youtube video in the modal to stop.

    I am not using bootstrap.

    Below is an example of just one of the modals in action.

    Any suggestions will help!

    Fiddle





    HTML
    Code:
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <a href="#" class="button" data-modal="#modal2">Modal2</a>
    
        <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate.</p>
    
    <div id="modal2" class="modal">
      <div class="modal-content">
        <a class="close">&times;</a>
        <h2>This is an image description 2</h2>
        <div class="video-container"><iframe class="youtube-video" width="560" height="315" src="https://www.youtube.com/embed/3VZFpwlXKpg?enablejsapi=1&mute=0&loop=1&version=3&playerapiid=ytplayer" frameborder="0" allowfullscreen></iframe>
        </div>
        <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate.</p>
      </div>
    </div>


    CSS
    Code:
    /* Modal */
    .modal {   position: fixed;   top: 0;   right: 0;   bottom: 0;   left: 0;   z-index: 9999999;   display: none;   background: rgba(255, 255, 255, 0.5); } 
    /* Fullscreen BG */
    .modal-content h2 {font-size: 1.0em; }
    .modal-content {   width: 80%;   height: 80vh;   overflow-x: hidden;   overflow-y: auto;   margin: 10% auto;   font-size: 1.2em; } 
    .close {line-height: 25px;   font-size: 1.0em;   position: absolute;   right: -24px;   text-align: center;   top: -6px width: 24px;   z-index: 9999999;   text-decoration: none;   font-weight: bold;   cursor: pointer; }
    .close:hover { color: grey; }
    
    /* Youtube */
    .video-container { overflow: hidden; position: relative; width:100%; }
    .video-container::after {padding-top: 56.25%; display: block; content: ''; } 
    .video-container iframe {position: absolute; top: 0; left: 0; width: 100%; height: 100%; }


    JS
    Code:
    //Model
    $(".button").on("click", function() {
      var modal = $(this).data("modal");
      $(modal).fadeIn();
    });
    //click away to close model
    $(".modal").on("click", function(e) {
      var className = e.target.className;
      if (className === "modal" || className === "close") {
        $(this).closest(".modal").fadeOut();
      }
    });
    //ESC close model
    $(document).keydown(function(e) {
      var code = e.keyCode || e.which;
      if (code == 27) $(".modal").fadeOut();
    });

  2.  


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 01:49 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com