Immersive pop-up interface displaying a variety of embedded videos simultaneously

I am a beginner in JavaScript and I came across a CodePen that does exactly what I need, but it currently only works for one embedded video.

What I aim to achieve is similar functionality, but with 6 videos.

(function ($) {

    'use strict';

    // Your custom JavaScript code goes here...

})(window.jQuery || window.Zepto);

// Initiate FitVid.js and other operations//

$(document).ready(function () {
    // Initialize FitVid.js plugin for all video containers
    $(".containiframeCeleb2").fitVids();
    $(".containiframeRiver2").fitVids();
    $(".containiframeBach").fitVids();
    $(".containiframeLouie").fitVids();
    $(".containiframeRiver1").fitVids();
    $(".containiframeCeleb1").fitVids();
    $(".containiframe").fitVids();

    // Iframe/player variables declaration
    
    var iframe = $('#video')[0];
    var player = $f(iframe);

    // Open on play function calls

    $('.play').click(function () {
        // Display content overlay when video is played
        $('.content').css('left', 0)
        $('.content').addClass('show')
        player.api("play");
    })

    // Other play functions for different video containers go here...

    // Close content overlay on click outside

    $('.content').click(function () {
        $('.content').removeClass('show')
        setTimeout(function () {
            $('.content').css('left', '-100%')
        }, 300);
        player.api("pause");
    })
});

/* CSS styles definition goes here... */
   
<!-- HTML structure for embedded videos and overlays -->

<body>
    <div class="content">

        <!-- Embedded video and close icon for each video container -->
        
        <!-- Fullscreen container configuration for multiple videos-->

    </div>

    <header>
        <!-- Play buttons for each video -->
    </header>

    <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
    <script src="js/index.js"></script>

</body>

</html>

For an ongoing update of the progress made, you can visit the JSFiddle link.

Answer №1

For a recent project that required embedding multiple videos, I utilized Bootstrap modal in the following way:

I implemented the use of Bootstrap modal as shown below:

<div id="videoModal" class="modal">
            <!-- Modal content -->
              <div class="modal-content">
                <span class="close">&times;</span>
                <iframe id="videoIframe" class="full-width height-480" 
  src="https://www.youtube.com/watch?v=UM-ZPAF2Dpw" frameborder="0" allowfullscreen></iframe>
                </div>
              </div>

You only need to add this code snippet once, and then within your button, pass the YouTube video ID like so:

<button onclick="showVideo('UM-ZPAF2Dpw')"><span class="glyphicon glyphicon-triangle-right"></span> Show Video 1</button>

You can include as many buttons as needed with different video IDs.

In your script file, make sure to have the following function defined:

function showVideo(youtubeID){

var url = 'https://www.youtube.com/embed/' + youtubeID 
document.getElementById('videoIframe').src = url;


// Get the modal
var modal = document.getElementById('videoModal');
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

modal.style.display = "block"; 
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
    modal.style.display = "none";
    document.getElementById('videoIframe').src = '';

}
// When the user clicks anywhere outside of the modal, close it
    window.onclick = function(event) {
        if (event.target == modal) {
    modal.style.display = "none";
    document.getElementById('videoIframe').src = '';
    }
}
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sorry, the provided text is already unique as it is an error message

I'm currently using the react-highlight-words package to highlight text inputted into a textbox After checking out the react-highlight-words documentation, I noticed that they are using searchWords as an array. https://www.npmjs.com/package/react-high ...

Troubleshooting an issue with Laravel's Bootstrap 5.2 dropdown functionality

After setting up a pre-configured navbar from the Bootstrap website, I noticed that the dropdown feature is not working. This issue arose with the latest version of Bootstrap 5.2 which was integrated into my Laravel project without any modifications to the ...

What is the best way to create a footer in this scenario and is there a method to perfectly center an

What is the best way to position the footer at the bottom of the page without overlapping the top content? Is there a method to center both the height and width of the header element on the page? Can you review the layout of this webpage and provide feed ...

What is the best way to ensure the remaining PHP script is executed after using json_encode()?

My current project involves creating a form with four input fields: name, email, phone, and message. To handle the submission process, I am utilizing JavaScript in conjunction with Ajax to send the user inputs to a PHP file for validation and mailing using ...

Struggling to make PayPal Cordova Plugin function properly in both production and sandbox modes

While using the cordova paypal plugin and switching to sandbox mode, I encountered an error. The plugin can be found at https://github.com/paypal/PayPal-Cordova-Plugin https://i.stack.imgur.com/lD2EH.png Running the plugin in PayPalEnvironmentNoNetwork m ...

The topic at hand pertains to a specific exercise featured in the well-known book Eloquent JavaScript

In this exercise, the final step is to create a recursive function that takes a joined list and an index as parameters. The function's purpose is to find the value in the object within the list at the specified index. The code I have written seems to ...

Type of element returned

Is there a way to retrieve the element type? I'm interested in applying the style of a class to HTML5 elements without using the class attribute. <!DOCTYPE> <html> <head> <title>My page</title> </head& ...

The Battle of Brainpower: Smarty vs. JavaScript/AJAX

One question I have is: Is there a specific guideline or convention for determining when to use "Smarty templating" versus using JavaScript Ajax calls to generate content? I have the ability to generate content dynamically using Ajax/JavaScript calls. Whi ...

What is the best way to customize CSS in Material UI?

When working with material UI and reactjs, I encountered an issue while trying to override the button color without affecting the tab colors (see screenshot). How can I achieve this using themes in material UI? Code: const theme = createMuiTheme({ p ...

Guide to aligning several texts to the right using Bootstrap 4 breadcrumbs

I am looking to implement a breadcrumb using Bootstrap 4.1 that displays the sitemap path on the left and login links on the right. Below is a visual representation of what I aim to achieve: Home/Blog/post Re ...

Cross domain widget ajax request

Our company offers a widget for clients to add to their websites. This widget requires a call to our website to validate user-entered data. However, due to domain restrictions, making ajax calls from the client's website to ours is not permitted. Is ...

Ways to eliminate class from HTML code

Trying to detect if a navigational element has a specific class upon click. If it has the class, remove it; if not, add it. The goal is to display an active state on the dropdown button while the dropdown is open. The active state should be removed when a ...

Encountering difficulties with a GraphQL structure within Apollo framework

I am currently in the process of building an Express server using Apollo 2. My schema is as follows: const typeDefs = gql `{ type Movie { id: ID! title: String year: String rating: String } type Query { ...

Creating a form that utilizes both jQuery and PHP to send the results, now including the complete code for reference

Full code update included. Changing the question: What occurs when all questions are answered in endQuiz, resulting in a user score? A form is displayed for the user to complete and submit to a designated email address. However, upon completing the form a ...

Tips for identifying the correct selectedIndex with multiple select elements present on one page

How can I maintain the correct selectedIndex of an HTMLSelectElement while having multiple select elements in a loop without any IDs? I am dynamically loading forms on a webpage, each containing a select element with a list of priorities. Each priority is ...

Organize the array by property name and include a tally for each group

My current data structure looks like this: var data = [ { MainHeader: Header1, SubHeader: 'one'}, { MainHeader: Header1, SubHeader: 'two'}, { MainHeader: Header2, SubHeader: 'three'}, { MainHeader: Header2, SubHea ...

"Creating an array object in the state of Reactjs - a step-by-step

As I am delving into the world of ReactJS, I am learning about changing state within this framework. One challenge I encountered was initializing an array object in state with an unknown length and updating it later using setState. Let me share the snippet ...

Learn how to extract data located between two specific tags using Java HtmlUnit

<span> <a></a> Hello <div>A plethora of irrelevant text</div> </span> My goal is to retrieve only the "Hello" from the webpage. While I can use XPath to target the span, calling .getTextContent() also includes the text ...

"Contrasting the initialization of state in the constructor with managing state

Can you explain the distinction between these two methods of initializing state in ES6 other than their access to props? constructor(props) { super(props); this.state = { highlighted: 5, backgroundColor: '#f3f3f3', ...

There appears to be an issue with displaying the graph

I am having trouble understanding how to transfer the values entered in the input to the graph that is displayed successfully. Although the update seems correct, nothing changes when I try to update it and the data remains stagnant. Page.vue <script&g ...