Clicking on the icon image that features a Background Video will trigger the video to play in a popup window originating from the same location

A background video is currently playing on the site. When the play icon is clicked, the video should start playing in a popup. The video should start playing continuously from the exact moment and position where it is clicked.

Check out the example here.

For instance, when the "Play" icon is clicked, the background video (set to autoplay) should start playing in the popup.

$( document ).ready(function() {
  $('#headerVideoLink').magnificPopup({
    type:'inline',
    midClick: true // Allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source in href.
  });
}); 
@charset "utf-8";
/* CSS Document */

#videoContainer {
  position: absolute;
  min-height: 25rem;
  width: 100%;
  overflow: hidden;
}

#videoContainer video {
  position: absolute;
  top: 50%;
  left: 50%;
  width: auto;
  height: auto;
  min-width: 100%;
  min-height: 100%;
  z-index: 0;
  -ms-transform: translateX(-50%) translateY(-50%);
  -moz-transform: translateX(-50%) translateY(-50%);
  -webkit-transform: translateX(-50%) translateY(-50%);
  transform: translateX(-50%) translateY(-50%);
}

#videoContainer .position {
  position: absolute;
  z-index: 2;
}

#videoContainer .overlay {
  position: absolute;
  top: 0;
  left: 0;
  background: #000000;
  height: 100%;
  width: 100%;
  opacity: 0.4;
  z-index: 1;
}

#headerPopup{
  width:100%;
  margin:0 auto;
}

#headerPopup video{
  width:100%;
  margin:0 auto;
}

.mfp-close-btn-in .mfp-close {
  color: #fff;
  opacity: 1;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.0.0/jquery.magnific-popup.min.js"><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.slim.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.0.0/magnific-popup.min.css" rel="stylesheet"/>
<link(href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<section id="videoContainer">
  <div class="overlay"></div>
  <video playsinline="playsinline" autoplay="autoplay" muted="muted" loop="loop">
    <source src="https://videos.dailymail.co.uk/video/mol/2015/10/21/404258251173707140/1024x576_404258251173707140.mp4" type="video/mp4">
  </video>
  <div class="container-fluid position h-100">
    <div class="d-flex h-100 text-center align-items-center">
      <div class="w-100">
        <a href="#headerPopup" id="headerVideoLink" target="_blank"><img src="https://image.flaticon.com/icons/png/512/0/375.png" alt="Smiley face" height="80" width="80"></a>
      </div>
    </div>
  </div>
  <div id="headerPopup" class="mfp-hide embed-responsive embed-responsive-21by9">
    <video playsinline="playsinline" autoplay="autoplay" controls="controls" muted="muted" loop="loop">
      <source src="https://videos.dailymail.co.uk/video/mol/2015/10/21/404258251173707140/1024x576_404258251173707140.mp4" type="video/mp4">
    </video>
  </div>
</section>

The video should start playing from a specific timestamp (x secs/mins) when clicked on the icon. In the Popup, it should continue playing from the same timestamp (x secs/mins).

Answer №1

Implementing a callback function in magnific popup allows you to update the currentTime of the background video to match the popup video using simple JavaScript.

Check out the Demo below:

$( document ).ready(function() {
  $('#headerVideoLink').magnificPopup({
    type:'inline',
    midClick: true, // Allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source in href.
    callbacks: {
      elementParse: function(item) {
        var bannerVid = $('#videoContainer').children('video')[0].currentTime;
        $('#videoContainer').children('video')[0].pause();
        $('#headerPopup').children('video')[0].currentTime = bannerVid;
        $('#headerPopup').children('video')[0].play();
      },
      close: function(){
        var vidTime = $('#headerPopup').children('video')[0].currentTime;
        $('#headerPopup').children('video')[0].pause();
        $('#videoContainer').children('video')[0].currentTime = vidTime;
        $('#videoContainer').children('video')[0].play();
      }
    }
  });
});
@charset "utf-8";
/* Styling for the video containers and overlays */

#videoContainer {
  position: absolute;
  min-height: 25rem;
  width: 100%;
  overflow: hidden;
}

#videoContainer video {
  position: absolute;
  top: 50%;
  left: 50%;
  width: auto;
  height: auto;
  min-width: 100%;
  min-height: 100%;
  z-index: 0;
  -ms-transform: translateX(-50%) translateY(-50%);
  -moz-transform: translateX(-50%) translateY(-50%);
  -webkit-transform: translateX(-50%) translateY(-50%);
  transform: translateX(-50%) translateY(-50%);
}

#videoContainer .position {
  position: absolute;
  z-index: 2;
}

#videoContainer .overlay {
  position: absolute;
  top: 0;
  left: 0;
  background: #000000;
  height: 100%;
  width: 100%;
  opacity: 0.4;
  z-index: 1;
}

#headerPopup {
  width: 100%;
  margin: 0 auto;
}

#headerPopup video {
  width: 100%;
  margin: 0 auto;
}

.mfp-close-btn-in .mfp-close {
  color: #fff;
  opacity: 1;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.0.0/magnific-popup.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.slim.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.0.0/jquery.magnific-popup.min.js"></script>

<section id="videoContainer">
  <div class="overlay"></div>
  <video playsinline="playsinline" autoplay="autoplay" muted="muted" loop="loop">
    <source src="https://videos.dailymail.co.uk/video/mol/2015/10/21/404258251173707140/1024x576_404258251173707140.mp4" type="video/mp4">
  </video>
  <div class="container-fluid position h-100">
    <div class="d-flex h-100 text-center align-items-center">
      <div class="w-100">
        <a href="#headerPopup" id="headerVideoLink" target="_blank"><img src="https://image.flaticon.com/icons/png/512/0/375.png" alt="Smiley face" height="80" width="80"></a>
      </div>
    </div>
  </div>
  <div id="headerPopup" class="mfp-hide embed-responsive embed-responsive-21by9">
    <video playsinline="playsinline" autoplay="autoplay" controls="controls" muted="muted" loop="loop">
      <source src="https://videos.dailymail.co.uk/video/mol/2015/10/21/404258251173707140/1024x576_404258251173707140.mp4" type="video/mp4">
    </video>
  </div>
</section>

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

Tips on adjusting the hover color in the data grid

I want to adjust the color of the Datagrid when hovering over it, does anyone know how to do this? The default color displayed is light blue, but I would like to change it to a different color. Can someone please assist me with this? Looking for document ...

Using Sweet Alert to enhance the user confirmation experience on your website

I need to replace the standard confirm dialog with a customized one using Sweet Alert. The JavaScript function I want to use is located in the MasterPage. function checkDelete() { swal({ title: "Are you sure?", text: "You will not be able to r ...

How can I efficiently retrieve the "value" of a cookie and store it in a .txt file using Python?

Seeking to automate certain requests, I am currently using selenium's get_cookie function to extract cookies from a website. The retrieved cookie data is returned as a dict structured like this: {'domain': 'website-name-here', &a ...

Errors are thrown when utilizing hydration with RTK Query

Looking for a solution with my local API and RTK Query, I've encountered an issue when implementing server-side rendering (SSR). Here's the code snippet I'm working with: const api = createApi({ reducerPath: 'data', baseQuery: ...

Replicate elements along with their events using jQuery

Every time I utilize ajax to dynamically generate new content using methods like .clone(), append(), etc., the newly created element loses all triggers and events that were programmed =( Once a copy is made, basic functionalities that work perfectly on ot ...

Is it possible to reset the value of a current request attribute?

I designed a homepage that consists of a header, a sidebar, and a div tag. When a user clicks on the "register" button, Registration.jsp is loaded into the div tag. After successfully submitting the registration form, I want to redirect it back to the sa ...

Discovering and sorting an array in Vue.js based on IDs

Hello everyone, I've been attempting to filter my results using the filter and includes methods but it doesn't seem to be working. Does anyone have a solution for this, perhaps involving includes or something similar? companies ids [1,2,3] user c ...

JavaScript function to toggle the visibility of navigation with a click of a button

I'm attempting to create a functionality in my code where the Open navigation button hides when the side navigation opens upon clicking. The desired behavior is for the openNav button to be hidden when it's clicked and then shown again when close ...

"Implementing a function to create files and folders within a context menu using jst

I'm currently working on a feature that allows users to create either a file or a folder by right-clicking on the menu. The context menu presents the options "file" and "folder," which is functioning correctly. However, the issue I am facing is with t ...

Having trouble displaying JSON response in Firefox console with Django

Code Snippet: from .views import get_data app_name = 'javascript' urlpatterns = [ path('', views.index, name='index'), path('api/data', get_data, name='api-data'), ] Views.py: from django.http ...

JavaScript For/in loop malfunctioning - Issue with undefined object property bug

Currently, I am tackling a basic For/in loop exercise as part of a course curriculum I am enrolled in. The exercise involves working with a simple object containing 3 properties and creating a function that takes two parameters - the object name and the it ...

Is it possible to enlarge the window screen using css?

After using zoom at 90%, everything was working fine until we introduced high charts. The hovering property doesn't display in the correct position. Looking for a solution to show a zoomed window on a small screen, like a laptop screen. Does anyone h ...

Forbidden access error in codeigniter with Ajax request 403

I'm struggling to send a value via Ajax to a Controller file in Codeigniter, but unfortunately I haven't been successful. Despite researching this issue and finding that it has been asked many times before, I still can't seem to find a solut ...

What is the best way to ensure the options/choices div reaches its ideal width?

Check out my StackBlitz project that I've set up In the styles.css file, you'll notice that I defined a fixed width of 650px for the option dropdown div, which is currently working fine @import '~bootstrap/dist/css/bootstrap.min.css'; ...

Switch div and expand/shrink the rest

Apologies for what might seem like a trivial question, but after working for a few hours now, I'm finding it difficult to wrap my head around this. My initial instinct is to handle this by manipulating the entire div structure with JavaScript, but I c ...

Javascript dynamically generates CSS animations

I need assistance creating a div with a CSS3 animated timer inside it when a button is clicked. Here is the code I have been working on: http://jsfiddle.net/arcco96/y5nov6rz/1/. Unfortunately, the div is not being created as expected. I believe the code sh ...

The customized sweet alert button is failing to trigger its designated function

I integrated vue-swal to show a pop-up dialog with customized functionality. However, I faced an issue while modifying the swal. In my modified version, there are 3 buttons each with specific actions that should be triggered upon clicking. But for some rea ...

When transitioning in Vue, pagination bullets shift to the left upon changing routes

While using Vue 3 and swiper.js, I encountered an issue where the pagination bullets move to the left when the route changes (component unmounted). It appears that the styling for the bullets and active button also disappear. I have created a reproduction ...

scroll after loading jQuery

I am attempting to automatically scroll to the div that displays the results of a jQuery load operation. Although the ajax load is functioning properly, the page does not automatically scroll after the load. Why isn't this test code accomplishing th ...

Opposite path matching with Next.js middleware

For my Next.js project, I have implemented a middleware and now I need it to only apply to routes that do not start with /api/. I have checked the documentation but couldn't find a similar example. Is there a way to achieve this without manually excl ...