ICL
Search…
Week 07
Multiple JS, DOM, Events and Callback Function
Week6 #7

1. Multiple JS files

You can keep your file in a separate js file.

2. DOM element and Callback Function

Document Object Model (DOM)

1
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.2/addons/p5.dom.min.js"></script>
Copied!

P5.dom library

Example

Example

Example

Callback function

Callback function is simple that

  1. 1.
    The function createButton is attached to the variable button.
  2. 2.
    And when the button is pressed, I want changeColor function os called.
    1
    button.mousePressed(changeColor);
    Copied!

Callback is simply one function is called and the other function is continuously called.

1
var button = createButton("Color??");
2
button.mousePressed(changeColor);
Copied!

Example

Assignment

  1. 1.
    Have multiple .js file (at least 2)
  2. 2.
    Have DOM element (it can be anything, button, slider, check, wordform, etc)
Last modified 3yr ago