0

我需要一个按钮来调整网页上的视频大小。该按钮必须在第一次单击时使视频变大,在第二次单击时使视频变小。我知道我需要一个变量来跟踪视频应该变大还是变小。

<!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>
4

1 回答 1

2

在点击事件上附加此功能;

var littleSize = false;
function changeSize()
{
  myVideo.width = littleSize ? 800 : 400;
  littleSize = !littleSize;//toggle boolean
}

http://jsfiddle.net/uNLHL/

于 2013-05-02T23:51:41.520 回答