javascript - 单击关闭图标时暂停或停止视频

标签 javascript css html

我想在按下关闭 (X) 图标时暂停/停止视频。 现在,当我单击 X 按钮时,视频会在后台继续播放。 我还希望关闭图标应该出现在播放器本身而不是播放器之外。

var hideStr = 'X', showStr = 'Show', hideClass = 'hide';
var buttons = document.querySelectorAll('video + button.close');
for(var b = 0; b < buttons.length; b++){
  var button = buttons[b];
  button.addEventListener('click', function(){
    var video = this.parentNode.childNodes[1];
    video.muted = !video.muted;
    video.classList.toggle (hideClass);
    if(this.textContent == hideStr) this.textContent = showStr;
    else this.textContent = hideStr;
  });
}
$('hideStr').click(function(){
  $(".playvideo").pause();       // Tag name used as a selector
});
div.relative {
    position: relative;
	 left: 00px;
}
.close {
    font-size: 10px;   
    position: inherit;
    top: 5px; right: 5px;
}
.hide {
    display: none;
}
<div>
    <video id="playvideo" width="450" controls="controls" >
	   <source src="http://corrupt-system.de/assets/media/sintel/sintel-trailer.m4v" type="video/mp4" />        
    </video>
	    <button class="close">X</button>
	</div>

最佳答案

let video = document.querySelector('video');

let close = document.querySelector('.close');


close.onclick = () => {
    video.pause();
}

在javascript中

关于javascript - 单击关闭图标时暂停或停止视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44967749/

相关文章:

javascript - HTML5/Javascript - 如何获取 Canvas 上形状/图像的坐标?

javascript - 使用 AJAX 调用恢复 session

javascript - 有没有办法在 jQuery 中检测隐式与显式 CSS 高度值?

javascript - "loading gif"背景图像问题 (IE/Edge)

javascript - MVC 和 HTML5 验证 : conflict with the decimal format

javascript - browserify 入门 : import local files?

css - 表格 td 中的 HTML/CSS 两种背景颜色和居中文本

javascript - 带有 <NavLink> 的 Blazor 子菜单

php - 复选框 onclick javascript 不会使 IE 中的文件上传元素为空

javascript - JavaScript 中的长文本滚动