Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to control video by JavaScript

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge points of this article "how to achieve JavaScript to control video", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can gain something after reading this article. Let's take a look at this "how to achieve JavaScript control video" article.

The specific code is as follows:

Documenttitle > figcaption {text-align: center;line-height: 150pxposition: "Microsoft Yahei"; font-size: 24px;}. Player {width: 720pxX height: 360px margin: 10px auto;border: 1px solid # 000X position: relative;border-radius: 6px;}. Player video {width: 720pxash height: 360px;}. Controls {width: 700pxheight: 40pxscape: rgba (255Lo 255r 00.3); position: absolute;bottom: 10pxleft: 10pxborderside radius }. Switch {position: absolute;width: 22pxposition height: red;left: 10pxscape top: 9pxborderbenefit: radius: 50%;}. Progress {width: 432pxpolitics height: 10pxpolitics position: absolute;background-color: rgba; left: 40pxtranstop: 15pxborderscape radius: 4pxscape: hidden;}. Curr-progress {width: 0% height: 100% leadership color: # fff;. Time {width: 120pxscape height: 20pxtextscape alignment: center;line-height: 20px alignment Font-size: 12pxfigcaption color: # fff;position: absolute;left: 510pxtostop: 10px;}. Extend {position: absolute;width: 20pxten height: 20pxscape: red;right: 10pxscape top: 10px;} style > head > video case figcaption > video > a > div > div > 00:00:00span > / 00:00:00span > div > a > div > div > figure > var video = document.querySelector ('video'); var playBtn = document.querySelector (' .switch'); var currProgress = document.querySelector ('.curr-progress'); var currTime = document.querySelector (' curr-time') Var totalTime = document.querySelector ('.total-time'); var extend = document.querySelector (' .extend'); var tTime = 0 video.play playBtn.onclick = function () {if (video.paused) {/ / if the video is paused video.play (); / / play () play load () reload pause () pause} else {video.pause () }} / / when the video can be played (loaded over the network), video.oncanplay = function () {tTime = video.duration; / / get the total video duration (in seconds) var tTimeStr = getTimeStr (tTime); totalTime [XSS _ clean] = tTimeStr;} / / when the video current playback time is updated, video.ontimeupdate = function () {var cTime = video.currentTime; / get the current playback time var cTimeStr = getTimeStr (cTime); console.log (cTimeStr) CurrTime [XSS _ clean] = cTimeStr;currProgress.style.width = cTime/tTime*100+ "%";} extend.onclick = function () {video.webkitRequestFullScreen (); / / Video full screen} / / change the time in seconds to the string function getTimeStr (time) {var h = Math.floor (time/3600); var m = Math.floor (time%3600/60); var s = Math.floor (time%60); h = h > = 10 seconds: "0" + h M = m > = 10Secretm: "0" + m + s = s > = 10cm: "0" + s return h+ ":" + m + ":" + s;} script > body > html > the above is about "how to control video by JavaScript". I believe everyone has a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about it, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report