CSc 337
LECTURE 13: DOM EXERCISES
CSc 337 LECTURE 13: DOM EXERCISES Exercise : Bouncing Ball Create a - - PowerPoint PPT Presentation
CSc 337 LECTURE 13: DOM EXERCISES Exercise : Bouncing Ball Create a page which contains an animated bouncing ball. You are given ball.html and ball.css , and you will write ball.js . (sample solution) The bounce area is 600px by 400px, and the
LECTURE 13: DOM EXERCISES
Create a page which contains an animated bouncing ball. You are given ball.html and
ball.css, and you will write ball.js. (sample solution)
speed by 1.
don't hard code those numbers)
A raptor is on the loose. Rawr! He wants to stomp the
eat them. The HTML and CSS are already written; start from this skeleton of attack.html. (sample solution)
Make it so that when the page first appears, 5 dogs are visible in the town. There are already 5 persons in the HTML, but they have no type. These are stored in the div with id of people as
divs with the class of person. Assign them the additional class dog when the page loads (while
retaining the class person).
<div id="people"> <!-- give these 5 divs the class 'dog' --> <div class="person"></div> <div class="person"></div> <div class="person"></div> <div class="person"></div> <div class="person"></div> </div>
Add! Adds 5 more dogs to the page (Later we will make it so that you can add cats too!). A person is a div with the classes of person and a class of either dog or cat. <button id="add">Add!</button>
function.
Kill! Randomly "kills" 1/5 of the dogs on the page. Kill them by giving them a class of splat (in addition to their existing person class, but in place of their type class such as dog or cat). <button id="kill">Kill!</button>
Dogs / Cats: Add a function that returns which type is currently selected. Modify the code from your previous two exercises so that you can choose which type to add or kill.
<label><input id="dogs" type="radio" name="type" /> Dogs</label> <label><input id="cats" type="radio" name="type" checked="checked" /> Cats</label>
Stomp! Makes the raptor move up or down by 75px and also kills 1/5 of both types. The raptor is an img tag with an id of raptor. <button id="stomp">Stomp!</button> HINT 1 (select): Move the raptor by setting his top style attribute to be either 10px or 85px. HINT 2 (select): Get an object's existing style properties with
window.getComputedStyle(element).propertyName .
HINT 3 (select): Stomp should kill 1/5 of both types - make sure to use the functions you have already written!