[英]onclick is not calling function
我正在嘗試制作一個覆蓋整個屏幕的按鈕,這是一個充當背景的視頻,點擊時應該暫停視頻。
即使光標在“標記”(不可見)按鈕並且我的代碼似乎正確(顯然不是),也沒有發生任何事情。
<!DOCTYPE html>
<html>
<head>
<style>
html, body { margin: 0; padding: 0; width: 100%; height: 100%; }
#button { width: 100%; height: 100%; opacity: 0; cursor: pointer; }
#myVideo { position: fixed; right: 0; bottom: 0; min-width: 100%; min-height: 100%; }
</style>
</head>
<body>
<video autoplay loop muted id="myVideo">
<source src="video.mp4" type="video/mp4">
</video>
<button id="button" type="button" onclick="myFunction()"></button>
<script>
var video = document.getElementById("myVideo");
function myFunction() {
video.pause();
}
</script>
</body>
</html>
在這里它有效。 不知道出了什么問題。
var video = document.getElementById("myVideo"); function stopVideo() { video.pause(); }
<!DOCTYPE html> <html> <head> <style> html, body { margin: 0; padding: 0; width: 100%; height: 100%; } #button { width: 100%; height: 100%; opacity: 0; cursor: pointer; } #myVideo { position: fixed; right: 0; bottom: 0; min-width: 100%; min-height: 100%; } </style> </head> <body> <video autoplay loop muted id="myVideo"> <source src="https://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_2mb.mp4" type="video/mp4"> </video> <button id="button" type="button" onclick="stopVideo()"></button> </body> </html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.