Friday, December 27, 2019

Lab 39 Event Capture, Propagation, Bubbling and Once

In this lab, I followed the instruction from JavaScript30 and recreated the Event Capture, Propagation, Bubbling and Once activity. First off, I made the HTML, CSS, and JavaScript files. Secondly, the <html>, <head>, <body>, <meta>, and <title> tags were already inserted in the HTML file. Thirdly, I typed in <link rel="stylesheet" type="text/css" href="Lab_39.css"> inside the <head> tags to link the CSS file with my HTML file. Fourthly, I typed in <script src="Lab_39.js" type="text/javascript"></script> inside the <body> tags which linked my JavaScript file with my HTML file. Inside the <body> tags, I typed the heading for the lab which has my name, date, and lab number with <div id="heading"><h1>Lab 39</h1><h2>Wei Jian Zhen</h2><h3>12/24/2019</h3></div>. Next I typed <div class="one"><div class="two"><div class="three"></div></div></div>. For the CSS, I typed in html {width: 100%; height: auto;} body {background-color: #00FFA8;
min-width: 100%; min-height: 100%;} to make the page size responsive and give the page a background color. #heading {text-align: center; font-size: 16px;} #copyright {font-size: 16px;
font-family: Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", "serif"; font-weight: normal; padding-left: 1%; padding-right: 1%;} to change the font of the beginning and ending text of the webpage. div {width: 100%; padding: 100px;} .one {background: thistle; cursor: pointer;} .two {background: mistyrose; cursor: pointer;} .three {background: coral; cursor: pointer;} to colorize the <divs> tags to look like the boxes in the console menu. For the JavaScript, I typed in:

 const divs = document.querySelectorAll('div');
  const button = document.querySelector('button');
  function logText(e) {
    console.log(this.classList.value);
    // e.stopPropagation(); // stop bubbling!
    // console.log(this);
  }
  divs.forEach(div => div.addEventListener('click', logText, {
    capture: false,
    once: true
  }));
  button.addEventListener('click', () => {
    console.log('Click!!!');
  }, {
    once: true
  });

This makes the <div> tags put out a console.log output from the console menu of the webpage. Lastly, I made the copyright notice with <p> and <div> tags. Knowing how to use JavaScript is useful to a web designer because it allows web designers to make website functional.

Link: http://techteach.us/Web2020/ZWeiJian/WCP/Labs/Lab_39/Lab_39.html



No comments:

Post a Comment