Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
Page has multiple videos for different viewports. How to play correct one using a single play button?

I'm using PLyr (https://plyr.io/) to output a couple of videos on the page - one displayed on desktop and the other on mobile.

There is a single custom button that toggle play.

The problem is that this event toggles play on both videos.

What I want is for the button to only target one video at a time given the viewport size.

This is a rough version of the code.

I'm using .each and trying to target individual players by players[index] but this isn't working

    <video id="video-1">
     <source src="" type="video/webm">
     <source src="" type="video/mp4">
    </video>

    <video id="video-2">
     <source src="" type="video/webm">
     <source src="" type="video/mp4">
    </video>

const players = Plyr.setup(".player");

// Expose player so it can be used from the console
window.player = players;

// Play each video
videoWrapper.each(function (index, video) {
    $('player').on("click touchend", function () {
        players[index].togglePlay();
    });
}

I suppose I could do something like the following but this seems messy. Are there any better options?


    $(window).resize(function() {
     if($(this).width() < 768) {
      $('#video-1').on("click", function () {
        playPause();
        anotherFun(); 
      });
        } else {
          $('#video-2').on("click touchend", function () {
            playPause();
            anotherFun(); 
        });
      }
    });

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!