Friday, December 27, 2019

Lab 36 Follow Along Link Highlighter

In this lab, I followed the instruction from JavaScript30 and recreated the Follow Along Link Highlighter 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_36.css"> inside the <head> tags to link the CSS file with my HTML file. Fourthly, I typed in <script src="Lab_36.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 36</h1><h2>Wei Jian Zhen</h2><h3>12/24/2019</h3></div>. Next I typed in <nav><ul class="menu"><li><a href="">Home</a></li><li><a href="">Order Status</a></li><li><a href="">Tweets</a></li><li><a href="">Read Our History</a></li><li><a href="">Contact Us</a></li></ul></nav> to create the navigation menu. <div class="wrapper"></div> with <p> and <a> tags inside it for the content of the webpage. Lastly, I made the copyright notice with <p> and <div> tags. For the CSS I did html {width: 100%; height: auto;} body {background-color: #00FFA8; min-width: 100%; min-height: 100%;} to give the webpage a background color and make the webpage responsive to screen size changes. #heading {text-align: center; font-size: 16px;} to center the heading of the lab. #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 copyright notice. .wrapper {margin: 0 auto; max-width: 500px; font-size: 20px; line-height: 2; position: relative;} to give the <div class="wrapper"></div> a size, positioning, and font. a {text-decoration: none; color: black; background: rgba(0,0,0,0.05); border-radius: 20px;} .highlight {transition: all 0.2s; border-bottom: 2px solid white; position: absolute; top: 0; background: white; left: 0; z-index: -1; border-radius: 20px; display: block; box-shadow: 0 0 10px rgba(0,0,0,0.2);} .menu {padding: 0; display: flex; list-style: none; justify-content: center; margin:100px 0;} .menu a {display: inline-block; padding: 5px; margin: 0 20px; color: black;} to colorize and position the link highlighter. For the JavaScript, I put:

// JavaScript Document
const triggers = document.querySelectorAll('a');
  const highlight = document.createElement('span');
  highlight.classList.add('highlight');
  document.body.appendChild(highlight);
  function highlightLink() {
    const linkCoords = this.getBoundingClientRect();
    console.log(linkCoords);
    const coords = {
      width: linkCoords.width,
      height: linkCoords.height,
      top: linkCoords.top + window.scrollY,
      left: linkCoords.left + window.scrollX
    };
    highlight.style.width = `${coords.width}px`;
    highlight.style.height = `${coords.height}px`;
    highlight.style.transform = `translate(${coords.left}px, ${coords.top}px)`;
  }
  triggers.forEach(a => a.addEventListener('mouseenter', highlightLink));

This makes the link highlighter move when hovered over or scrolled.Knowing how to use link highlighters is useful to a web designer because it allows the web designer to make more clean designs and UI.

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


No comments:

Post a Comment