Skip to content

Latest commit

 

History

History
32 lines (28 loc) · 1.75 KB

readme.md

File metadata and controls

32 lines (28 loc) · 1.75 KB

Given an empty HTML document, use raw JS (and optionally some CSS) to...
Reminder: Inspection tools are your friend.

Set 1

  1. create and insert an empty div on the page. It should have
  • width and height
  • positioning
  • top and left coordinates
  • background color expressed as rgba
  1. write a function "buildBox" that creates and inserts that div on the page and returns it.
  2. write a function "randInRange" that generates a random integer, given a range of possible values (min & max).
  3. write a function "setStyles" that accepts an element and sets width, height, top, left, and the color to random values. Use logically derived ranges for the top and left.

Set 2

  1. using setTimeout, run setStyles on the box once every second, continuously. Ok, then turn it off.
  2. create a new loop that smoothly animates the position of the box, moving it 60 times per second. 1px horizontal and 1px vertical is a good velocity to start.
  3. set the initial velocity to be randomly generated, within reasonable bounds.
  4. update the animation such that the box changes direction predictably when it touches the edge of the viewport.
  5. if you haven't already, set the velocity to change randomly (within acceptible bounds!) when it touches the edge of the viewport.

Set 3

  1. update buildBox to be a constructor for a new Box Object prototype. It should have as properties
  • a styled HTML element that exists in the DOM
  • its position (x & y)
  • its size (width & height)
  • its velocity (x & y)
  1. write a method "bounce" to handle the speed and direction changes.
  2. attach "bounce" to click events on the Box, so it changes direction and speed when clicked upon.
  3. using a loop and an array, create 100 Boxes and store them for later reference.