// This is called a 'comment'
// It's here for you to read
// JavaScript doesn't care what you type in a comment.
// Put your code below to animate Douglas!
function moveUpDown(e) {
var robotPart = e.target;
var top = 0;
var id = setInterval(frame, 10) // draw every 10ms
function frame() {
// the frame function makes animation frames.
robotPart.style.top = top + '%';
// this line changes the position of the clicked part.
top++;
// this line adds 1 to the top variable.
if (top === 20){
// this checks the value of top and does the next thing
// unless top is equal to 20.
clearInterval(id);
// This statement runs when top is equal to 20.
// It stops the animation.
}
}
}
function moveRightLeft(e) {
var robotPart = e.target;
var left = 0;
var id = setInterval(frame, 10) // draw every 10ms
function frame() {
robotPart.style.left = left + '%';
left++;
if (left === 70){
clearInterval(id);
}
}
}
var rightEye = document.getElementById("righteye");
rightEye.addEventListener("click", moveUpDown);
var leftEye = document.getElementById("lefteye");
leftEye.addEventListener("click", moveUpDown)
var leftArm = document.getElementById("leftarm");
leftArm.addEventListener("click", moveRightLeft);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.