1、开始与暂停
<style>
*{
margin: 0px;
padding: 0px;
}
.video_player{
position: relative;
width: 1000px;
height: 500px;
margin: 0px auto;
}
video{
position: absolute;
width: 1000px;
height: 500px;
left: 0px;
top: 0px;
}
.menu{
position: absolute;
width: 100%;
height: 50px;
background-color: rgba(0,0,0,0.5);
bottom: 0px;
display: none;
}
.play{
position: absolute;
width: 100px;
height: 30px;
border: 1px solid white;
text-align: center;
line-height: 30px;
color: white;
border-radius: 10px;
margin-left: 20px;
top: 50%;
margin-top: -15px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="video_player">
<!--video与audio是一样的,只比audio多一个视频,方法都一样 -->
<video src="contenteditable.mov" controls></video><!-- 加controls才能有播放栏 -->
<div class="menu">
<div class="play">播放</div>
</div>
</div>
<script>
var videoPlayer = document.getElementsByClassName("video_player")[0];
var video = videoPlayer.getElementsByTagName("video")[0];
var menu = document.getElementsByClassName('menu')[0];
var play = document.getElementsByClassName("play")[0];
videoPlayer.onmouseenter = function() {
menu.style.display = "block";
}
videoPlayer.onmouseleave = function(){
menu.style.display = "none";
}
play.onclick = function(){
if(video.paused){
video.play();
play.innerHTML = "暂停";
}else{
video.pause();
play.innerHTML = "播放";
}
}
</script>
</body>