Lab #38 Event Capture, Propagation...
Lab #38 is titled, "Event Capture, Propagation". This lab demonstrates how events work in JavaScript and how you can get the information of what is clicked on a page, demonstrated by a div with 3 layers and a button. In order to get the data, you would have to open the console and click on either of the rectangles or the button to get a response. (The colors in the screenshot might have been changed on the actual website).
To make this feature function properly was very simple. I created 3 divs in my HTML document and then created a CSS for each one and gave them their own color. The same applies to the one-button I created. To make the console logs, I used JavaScript to select the divs and when you click a div, it will console.log the name of that div in terms of class. For example, the biggest box is "one", the second biggest is "two" and the smallest div is named "three". The event listener checks for when you click any of the divs. When it does detect you clicked on, it will display in console with the one you clicked. However, if you click the smallest div, it will record all 3 because it contains them all. When you click the 2nd div, it will record the 1st and 2nd div as being clicked. Clicking the biggest box will only record the "one" div being clicked. Lastly, the button is on its own and will say in the console once it is clicked.
Web designers can experiment with event listeners to make their website more interactable. For example, when you click a button, instead of just displaying something in console, you can make something else happen, like text pop-up, an animation taking place, etc.
To make this feature function properly was very simple. I created 3 divs in my HTML document and then created a CSS for each one and gave them their own color. The same applies to the one-button I created. To make the console logs, I used JavaScript to select the divs and when you click a div, it will console.log the name of that div in terms of class. For example, the biggest box is "one", the second biggest is "two" and the smallest div is named "three". The event listener checks for when you click any of the divs. When it does detect you clicked on, it will display in console with the one you clicked. However, if you click the smallest div, it will record all 3 because it contains them all. When you click the 2nd div, it will record the 1st and 2nd div as being clicked. Clicking the biggest box will only record the "one" div being clicked. Lastly, the button is on its own and will say in the console once it is clicked.
Web designers can experiment with event listeners to make their website more interactable. For example, when you click a button, instead of just displaying something in console, you can make something else happen, like text pop-up, an animation taking place, etc.

Comments
Post a Comment