Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- (A) MAIN MENU -->
<div id="screenA">
  <div class="mItem" onclick="cards.view('v')">
    <div class="mi">view_array</div>
    <div class="mTxt">View Cards</div>
  </div>
  <div class="mItem" onclick="cards.view('m')">
    <div class="mi">edit</div>
    <div class="mTxt">Manage Cards</div>
  </div>

  <!-- (X) VISIT CODE-BOXX -->
  <div class="mItem" id="code-boxx">
    Visit
    <a href="https://code-boxx.com/javascript-drawing-app/" target="_blank">
      Code Boxx
    </a> for more details.
  </div>
</div>

<!-- (B) MANAGE/VIEW CARDS -->
<div id="screenB" class="hide">
  <!-- (B1) CARDS WRAPPER -->
  <div id="bCard"></div>

  <!-- (B2) CONTROLS -->
  <div id="bManage">
    <div class="mi" onclick="cards.screen(0)">reply</div>
    <div class="mi bManage" onclick="cards.delete()">clear</div>
    <div class="mi bManage" onclick="cards.add()">add</div>
    <div class="mi" onclick="cards.move()">navigate_before</div>
    <div class="mi" onclick="cards.move(1)">navigate_next</div>
    <div id="bCardCount">
      <span id="bCardNow"></span> / <span id="bCardAll"></span>
    </div>
  </div>
</div>
              
            
!

CSS

              
                /* (A) MATERIAL ICONS */
@font-face{font-family:"Material Icons";font-style:normal;font-weight:400;src:url(https://fonts.gstatic.com/s/materialicons/v138/flUhRq6tzZclQEJ-Vdg-IuiaDsNc.woff2) format('woff2')}
.mi{font-family:"Material Icons";font-weight:400;font-style:normal;font-size:60px;line-height:1;letter-spacing:normal;text-transform:none;display:inline-block;white-space:nowrap;word-wrap:normal;direction:ltr;-webkit-font-feature-settings:"liga";-webkit-font-smoothing:antialiased}

/* (B) WHOLE PAGE & SHARED */
* {
  font-family: Arial, Helvetica, sans-serif;
  box-sizing: border-box;
}
body, #screenA, #screenB {
  padding: 0; margin: 0;
  width: 100vw; height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  flex-direction: column;
}
body {
  background: rgb(79,85,171);
  background: linear-gradient(71deg, rgb(79,85,171) 0%, rgb(103,126,218) 77%, rgb(62,69,147) 100%);
}
.hide { display: none !important; }

/* (C) MAIN MENU */
#screenA { text-align: center; }
.mItem {
  width: 300px;
  border-radius: 10px;
  padding: 40px 0;
  margin-bottom: 10px;
  color: #fff;
  background: #363578;
  cursor: pointer;
}
.mItem:hover {
  color: #333;
  background: #f5ee03;
}
.mItem .mTxt { font-size: 24px; }

/* (D) VIEW CARDS */
/* (D1) CARD WARPPER */
#bCard {
  width: 80%; height: 60%;
  position: relative;
}

/* (D2) CARD BACK & FRONT */
.card { cursor: pointer; }
.card, .front, .back {
  width: 100%; height: 100%;
  position: absolute;
}
.front, .back {
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 60px;
  border-radius: 10px;
  backface-visibility: hidden;
}
.front, .mFront {
  color: #2e189a;
  background: #fff;
}
.back, .mBack {
  color: #fff;
  background: #2e189a;
}
.back { transform: rotateY(180deg); }
.mFront, .mBack {
  display: block;
  width: 100%; height: 50%;
  padding: 20px;
  resize: none;
  font-size: 20px;
}

/* (D3) CARD FILP */
.card {
  transition: transform 0.5s;
  transform-style: preserve-3d;
}
#bCard .card.flip { transform: rotateY(180deg); }

/* (E) CARD CONTROLS */
#bManage {
  padding: 10px;
  color: #fff;
  display: flex;
  align-items: center;
}
#bManage div.mi:hover {
  color: #f5ee03;
  cursor: pointer;
}
#bCardCount { font-size: 24px; }

/* (X) NOT IMPORTANT */
#code-boxx {
  text-align: center;
  font-weight: 600;
}
#code-boxx a {
  display: inline-block;
  border: 0;
  padding: 5px;
  text-decoration: none;
  background: #b90a0a;
  color: #fff;
}
              
            
!

JS

              
                var cards = {
  // (A) PROPERTIES
  data : null, // flashcards data array
  cNow : null, // current flashcard
  cMode : null, // current mode - "v"iew or "m"anage
  hScr : null, // html screens
  hCard : null, // html card wrapper

  // (B) INIT APP
  init : () => {
    // (B1) RESTORE CARDS FROM LOCALSTORAGE
    cards.data = localStorage.getItem("cards");
    if (cards.data == null) { cards.data = []; }
    else { cards.data = JSON.parse(cards.data); }

    // (B2) GET HTML ELEMENTS
    cards.hScr = [
      document.getElementById("screenA"),
      document.getElementById("screenB")
    ];
    cards.hCard = document.getElementById("bCard");
  },

  // (C) SWTICH HTML SCREEN
  screen : (i) => { for (let j in cards.hScr) {
    if (i==j) { cards.hScr[j].classList.remove("hide"); }
    else { cards.hScr[j].classList.add("hide"); }
  }},

  // (D) UPDATE CURRENT & TOTAL CARDS
  count : () => {
    document.getElementById("bCardNow").innerHTML = cards.data.length==0 ? 0 : cards.cNow + 1;
    document.getElementById("bCardAll").innerHTML = cards.data.length;
  },
  
  // (E) VIEW/MANAGE CARDS
  view : (mode) => {
    // (E1) VIEW MODE - CONTINUE ONLY WHEN THERE ARE CARDS
    if (mode=="v" && cards.data.length==0) {
      alert("Add some cards first...");
      return;
    }

    // (E2) UPDATE FLAGS & CARDS COUNT
    cards.cMode = mode;
    cards.cNow = 0;
    cards.count();
    
    // (E3) SHOW/HIDE "MANAGE CARD" CONTROLS
    if (mode=="v") { for (let i of document.querySelectorAll(".bManage")) {
      i.classList.add("hide");
    }} else { for (let i of document.querySelectorAll(".bManage")) {
      i.classList.remove("hide");
    }}
    
    // (E4) DRAW CARD & SHOW
    cards.draw();
    cards.screen(1);
  },
  
  // (F) DRAW CARD
  draw : () => {
    // (F1) VIEW MODE CARD
    if (cards.cMode=="v") {
      cards.hCard.innerHTML = `<div class="card" onclick="this.classList.toggle('flip')">
      <div class="front">${cards.data[cards.cNow][0]}</div>
      <div class="back">${cards.data[cards.cNow][1]}</div>
      </div>`;
    }

    // (F2) MANAGE MODE CARD
    else {
      if (cards.data.length==0) {
        cards.hCard.innerHTML = `<div class="mFront">Add a card first.</div>`;
      } else {
        // @TODO
        cards.hCard.innerHTML = `
        <textarea class="mFront" onchange="cards.update(this.value, 1)">${cards.data[cards.cNow][0]}</textarea>
        <textarea class="mBack" onchange="cards.update(this.value)">${cards.data[cards.cNow][1]}</textarea>`;
      }
    }
  },

  // (G) LAST/NEXT CARD
  move : (next) => {
    // (G1) UPDATE CURRENT CARD
    if (next) { cards.cNow++; }
    else { cards.cNow--; }
    if (cards.cNow >= cards.data.length) { cards.cNow = 0; }
    if (cards.cNow < 0) { cards.cNow = cards.data.length - 1; }

    // (G2) UPDATE HTML INTERFACE
    cards.count();
    cards.draw();
  },

  // (H) SAVE CARD DATA TO LOCALSTORAGE
  save : () => {
    localStorage.setItem("cards", JSON.stringify(cards.data));
  },

  // (I) ADD EMPTY CARD
  add : () => {
    cards.data.splice(cards.cNow, 0, ["Front", "Back"]);
    cards.save();
    cards.count();
    cards.draw();
  },
  
  // (J) UPDATE CURRENT CARD
  update : (txt, side) => {
    if (side) { cards.data[cards.cNow][0] = txt; }
    else { cards.data[cards.cNow][1] = txt; }
    cards.save();
  },
  
  // (K) DELETE CURRENT CARD
  delete : () => { if (cards.data.length!=0) {
    cards.data.splice(cards.cNow, 1);
    cards.save();
    if (cards.data.length == 0) { cards.cNow = 0; }
    else if (cards.cNow+1 >= cards.data.length) {cards.cNow = cards.data.length-1; }
    cards.count();
    cards.draw();
  }}
};
window.onload = cards.init;
              
            
!
999px

Console