Friday, December 27, 2019

Lab 19 Flex Panel Gallery

In this lab, I followed the instruction from JavaScript30 and recreated the Flex Panel Gallery 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_19.css"> inside the <head> tags to link the CSS file with my HTML file. Fourthly, I typed in <script src="Lab_19.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 19</h1><h2>Wei Jian Zhen</h2><h3>12/24/2019</h3></div>. After the heading <div> tags, I typed in more <div> tags and inside those <div> tags, I typed in <p> tags which made the flex panel gallery text. Next, I typed in <a> tags inside <div> tags that made the flex panel gallery images. 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. Then I did:

*, *:before, *:after {
      box-sizing: inherit;
    }
    .panels {
      min-height: 100vh;
      overflow: hidden;
      display: flex;
    }
    .panel {
      background: #6B0F9C;
      box-shadow: inset 0 0 0 5px rgba(255,255,255,0.1);
      color: white;
      text-align: center;
      align-items: center;
      /* Safari transitionend event.propertyName === flex */
      /* Chrome + FF transitionend event.propertyName === flex-grow */
      transition:
        font-size 0.7s cubic-bezier(0.61,-0.19, 0.7,-0.11),
        flex 0.7s cubic-bezier(0.61,-0.19, 0.7,-0.11),
        background 0.2s;
      font-size: 20px;
      background-size: cover;
      background-position: center;
      flex: 1;
      justify-content: center;
      display: flex;
      flex-direction: column;
    }
    .panel1 { background-image:url("photo-1495472552284-3f8aecebe3d1.jfif"); }
    .panel2 { background-image:url("photo-1511898634545-c01af8a54dd5.jfif"); }
    .panel3 { background-image:url("photo-1494280456775-9390bbf68598.jfif"); }
    .panel4 { background-image:url("photo-1531482615713-2afd69097998.jfif"); }
    .panel5 { background-image:url("photo-1529518152792-d08317b26e22.jfif"); }
    /* Flex Items */
    .panel > * {
      margin: 0;
      width: 100%;
      transition: transform 0.5s;
      flex: 1 0 auto;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .panel > *:first-child { transform: translateY(-100%); }
    .panel.open-active > *:first-child { transform: translateY(0); }
    .panel > *:last-child { transform: translateY(100%); }
    .panel.open-active > *:last-child { transform: translateY(0); }
    .panel p {
      text-transform: uppercase;
      font-family: 'Amatic SC', cursive;
      text-shadow: 0 0 4px rgba(0, 0, 0, 0.72), 0 0 14px rgba(0, 0, 0, 0.45);
      font-size: 2em;
    }
 
    .panel p:nth-child(2) {
      font-size: 4em;
    }
    .panel.open {
      flex: 5;
      font-size: 40px;
    }
 
    @media only screen and (max-width: 600px) {
      .panel p {
        font-size: 1em;
      }
    }

which animate the panels, give backgrounds to the panels, position the panels, and change the fonts of the panels.

For the JavaScript I put:


// JavaScript Document

const panels = document.querySelectorAll('.panel');
    function toggleOpen() {
      console.log('Hello');
      this.classList.toggle('open');
    }
    function toggleActive(e) {
      console.log(e.propertyName);
      if (e.propertyName.includes('flex')) {
        this.classList.toggle('open-active');
      }
    }
    panels.forEach(panel => panel.addEventListener('click', toggleOpen));
    panels.forEach(panel => panel.addEventListener('transitionend', toggleActive));

which open the flex panels and shows the full message.

Knowing how to make flex panel galleries is useful for a web designer because it allows the web designer to do their job more efficiently and effectively.

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


No comments:

Post a Comment