Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
172 views
in Technique[技术] by (71.8m points)

javascript - script to check if a video is playing and not restart

Okay, that's phrased awkwardly, but what I'm looking for is a script that checks, onclick if a video is playing, and if it is, don't start playing it again.
It's for a page that has six thumbs in an array that each play a video, and you're not supposed to be able to restart the video(which means its acting like its not selected)
how would I be able to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To prevent clicking from doing anything to the video you can do this:

$("video").click(function(e) {
   e.preventDefault();
   return false;
});

To determine if the video is playing or not you can read this previous question: Detect if HTML5 Video element is playing

So you'll want to read that and then do something like:

$("video").click(function(e) {
   if (videoStatus === "playing") {
      e.preventDefault();
      return false;
   }
});

Let me know if you're not using jQuery and I'll update my answer to use getElementsByTagName.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...