What's new

Welcome to the forum 👋, Visitor

To access the forum content and all our services, you must register or log in to the forum. Becoming a member of the forum is completely free.

Stop Video on Modal Close

r43gf34gsf

New member
Joined
Jun 12, 2019
Messages
7
Reaction score
0
HTML Coins
0
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
<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="
" 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

/* 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
//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();
});
 

Theme customization system

You can customize some areas of the forum theme from this menu.

  • Wide/Narrow view

    You can control a structure that you can use to use your theme wide or narrow.

    Grid view forum list

    You can control the layout of the forum list in a grid or ordinary listing style structure.

    Picture grid mode

    You can control the structure where you can open/close images in the grid forum list.

    Close sidebar

    You can get rid of the crowded view in the forum by closing the sidebar.

    Fixed sidebar

    You can make it more useful and easier to access by pinning the sidebar.

    Close radius

    You can use the radius at the corners of the blocks according to your taste by closing/opening it.

  • Choose the color combination that reflects your taste
    Background images
    Color gradient backgrounds
Back