我尝试使用基本的javascript脚本缩小视频(),但由于某种原因,它并没有改变。我甚至尝试使用chrome dev工具将其缩小,但它只是缩小尺寸。
这是基本脚本 -
window.onload = function() {
var videos = document.getElementsByTagName('video');
for(var i=0;i<videos.length;i++) {
videos.item(i).addEventListener("loadedmetadata", function(e) {
//Tried using target and videoWidth
//Both didn't work
e.srcElement.clientWidth = "480";
console.log(e);
});
}
}
答案 0 :(得分:0)
查看以下代码:
<video width="720" height="405" controls preload="auto">
<source src="myvideo.mp4" type="video/mp4" />
</video>
<script type="text/javascript">
var videos = document.getElementsByTagName('video');
for(var i=0;i<videos.length;i++) {
console.log(videos[i]);
videos[i].addEventListener("loadedmetadata", function(){
console.log('loadedmetadata');
this.setAttribute("width","480");
this.setAttribute("height","270");
});
}
</script>
要修复代码,有两件事需要解决: