我需要一个按钮来调整网页上的视频大小。第一次单击时按钮必须使视频变大,第二次单击时按钮使视频变小。我知道我需要一个变量来跟踪视频是应该变大还是变小。
<!DOCTYPE html>
<html>
<head>
<title>Simple animations in HTML5</title>
</head>
<body>
<h2> Optical Illusion </h2>
<video id="illusion" width="640" height="480" controls>
<source src="Illusion_movie.ogg">
</video>
<div id="buttonbar">
<button onclick="changeSize()">Big/Small</button>
</div>
<p>
Watch the animation for 1 minute, staring at the centre of the image. Then look at something else near you.
For a few seconds everything will appear to distort.
Source: <a href="http://en.wikipedia.org/wiki/File:Illusion_movie.ogg">Wikipedia:Illusion movie</a>
</p>
<script>
var myVideo=document.getElementById("illusion");
var togglesize = false
if togglesize == true
{
function changeSize()
{
myVideo.width=800;
togglesize = false;
}
}
else
{
function changeSize()
{
myVideo.width = 400;
togglesize = true;
}
}
</script>
</body>
</html>
答案 0 :(得分:2)
在点击事件上附加此功能;
var littleSize = false;
function changeSize()
{
myVideo.width = littleSize ? 800 : 400;
littleSize = !littleSize;//toggle boolean
}