1、开始与暂停

  1. <style>
  2. *{
  3. margin: 0px;
  4. padding: 0px;
  5. }
  6. .video_player{
  7. position: relative;
  8. width: 1000px;
  9. height: 500px;
  10. margin: 0px auto;
  11. }
  12. video{
  13. position: absolute;
  14. width: 1000px;
  15. height: 500px;
  16. left: 0px;
  17. top: 0px;
  18. }
  19. .menu{
  20. position: absolute;
  21. width: 100%;
  22. height: 50px;
  23. background-color: rgba(0,0,0,0.5);
  24. bottom: 0px;
  25. display: none;
  26. }
  27. .play{
  28. position: absolute;
  29. width: 100px;
  30. height: 30px;
  31. border: 1px solid white;
  32. text-align: center;
  33. line-height: 30px;
  34. color: white;
  35. border-radius: 10px;
  36. margin-left: 20px;
  37. top: 50%;
  38. margin-top: -15px;
  39. cursor: pointer;
  40. }
  41. </style>
  42. </head>
  43. <body>
  44. <div class="video_player">
  45. <!--videoaudio是一样的,只比audio多一个视频,方法都一样 -->
  46. <video src="contenteditable.mov" controls></video><!-- controls才能有播放栏 -->
  47. <div class="menu">
  48. <div class="play">播放</div>
  49. </div>
  50. </div>
  51. <script>
  52. var videoPlayer = document.getElementsByClassName("video_player")[0];
  53. var video = videoPlayer.getElementsByTagName("video")[0];
  54. var menu = document.getElementsByClassName('menu')[0];
  55. var play = document.getElementsByClassName("play")[0];
  56. videoPlayer.onmouseenter = function() {
  57. menu.style.display = "block";
  58. }
  59. videoPlayer.onmouseleave = function(){
  60. menu.style.display = "none";
  61. }
  62. play.onclick = function(){
  63. if(video.paused){
  64. video.play();
  65. play.innerHTML = "暂停";
  66. }else{
  67. video.pause();
  68. play.innerHTML = "播放";
  69. }
  70. }
  71. </script>
  72. </body>