Let's take a look at the application of an html5 video element for simple control.
Watch the video here, study it online, or download it to favorites. Video loading may be slow. Please be patient.
First, let's look at html5. Here we mainly use video elements. The usage of video elements is as follows:
<Video width = "800" height = "" poster = "pic url"> <source src = "myvideo.mp4" type = "video/mp4"> </source> <source src = "myvideo. ogv "type =" video/ogg "> </source> <source src =" myvideo. webm "type =" video/webm "> </source> <object width =" "height =" "type =" application/x-shockwave-flash "data =" myvideo.swf"> <param name = "movie" value = "myvideo.swf"/> <param name = "flashvars" value = "autostart?true&file=myvideo.swf"/> </object> the current browser does not support direct video playback., click here to download the video: <a href = "myvideo. webm "> download video </a> </video>
We only use the mp4 format here. The Code is as follows.
<Div id = "videoContainer"> <video id = "video" poster = "img/img.jpg"> <source src = "http://media.w3.org/2010/05/sintel/trailer.mp4" type = "video/mp4"> </ source> the current browser does not support direct video playback, click here to download the video: <a href = "http://media.w3.org/2010/05/sintel/trailer.mp4"> download the video </a> </video> <button id = "videoCtrl" onclick = "p (); "value =" play "> play </button> </div>
In css, we mainly need to implement the # videoContainer entry animation and the hover animation of the control button.
# VideoContainer's entry animation and style settings are as follows:
@keyframes bounceInLeft {0% {opacity: 0;transform: translateX(-2000px)}60% {opacity: 1;transform: translateX(30px)}80% {transform: translateX(-10px)}100% {transform: translateX(0)}}#videoContainer {position: absolute;margin: auto;left: 0;right: 0;top: 0;bottom: 0;width: 600px;height: 336px;border: 10px solid #fff;box-shadow: 0 0 10px rgba(0,0,0,.5);animation: bounceInLeft 1s .2s ease both;}
Control Button # Set the videoCtrl style and the hover animation.
#video {width: 600px;}#videoCtrl {border: none;cursor: pointer;position: absolute;margin: auto;left: 0;right: 0;top: 0;bottom: 0;width: 50px;height: 50px;border-radius: 50%;opacity: 0;transition: all 1s;transform: rotateX(0deg);}#videoContainer:hover #videoCtrl {opacity: 1;transform: rotateX(360deg);}
Finally, let's look at the js
var video = document.getElementById("video");var ctrl = document.getElementById("videoCtrl");function p() {if (video.paused) {video.play();ctrl.innerText = "stop";} else {video.pause();ctrl.innerText = "play";}}
Finished, mainly learning the use of video and the use of common attributes and methods of video.
For more information about html5 videos, see the tutorial.
I hope it will be helpful to you. Thank you for your support. Thank you!
---------------------------------------------------------------
Front-end development of whqet, focus on web Front-end development technology, and share webpage-related resources.
---------------------------------------------------------------