Reputation: 247
I need a button that will resize a video on the webpage. The button must on first click make the video bigger, and on second click make the video smaller. I understand I need a variable to keep track of whether the video should be made bigger or smaller.
<!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>
Upvotes: 0
Views: 3442
Reputation: 1479
Attache this function on click event;
var littleSize = false;
function changeSize()
{
myVideo.width = littleSize ? 800 : 400;
littleSize = !littleSize;//toggle boolean
}
Upvotes: 2