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

100
Views
Switch video source on click

For example: Section 1 HOME: has a video loop background, "video source 1" I want to change the video source by clicking on the video in section 1 to "video source 2",

but video2 has only to be played one time and has to switch back again to video1

How do I fix that

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can try something like this:

  • Create a Boolean for true/false as your "If played once" variable. Set it to = false;...

  • Give the (background) <video> tag an ID in the tag setup.

  • Add a "click" listener to the <video> tag.

  • The click handling function should get video object by ID...

  • Have an if statement to check If (played_Once == false)

  • Inside the if, you can set myVideoID.src = "other_video.mp4 and then do also:
    myVideoID.load();
    myVideoID.play();
    played_Once = true;

  • You also need to add an "on ended" listener to the video object, where the handling function will change src in the same way as the steps above, back to the original video, remove the listener for "ended" at this point

about 4 years ago · Juan Pablo Isaza Report
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!