Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                <html lang="ja">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>TerraceTechフロントエンドエンジニア養成所</title>
</head>

<body>
  <div id="js-wrapper" class="wrapper">
    <ul id="js-ul"></ul>
    <button type="button" id="js-modal-btn" class="modal__open-btn">modal open</button>
  </div>
  <div class="modal" id="js-modal">
    <form>
      <p class="form-text">Tell me about yourself.</p>
      <dl>
        <div class="form-item">
          <dt><label for="name">Name :</label></dt>
          <dd><input type="text" name="name" id="name"></dd>
        </div>
        <div class="form-item">
          <dt><label for="number">What is your favorite number?</label></dt>
          <dd><input type="number" name="number" id="number"></dd>
        </div>
      </dl>
      <input type="submit" value="submit" id="js-request-btn">
    </form>
    <a href="" class="modal__close-icon" id="js-modal-close-icon"><img src="https://i.postimg.cc/1tsRQ88J/2.png" alt=""></a>
  </div>
 
</body>

</html>

              
            
!

CSS

              
                .modal__open-btn {
  background-color: #fff;
  display: flex;
  justify-content: center;
  margin: 30px auto 0;
  cursor: pointer;
  background-color: rgb(176, 212, 241);
  border: none;
  border-bottom: 5px solid rgb(93, 151, 199);
  padding: 20px 0;
  width: 200px;
  max-width: 100%;
  font-size: 18px;
  border-radius: 50px;
}

.modal__open-btn:hover {
  margin-top: 33px;
  border-bottom: 2px solid rgb(93, 151, 199);
}

.modal {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30%;
  transform: translate(-50%, -50%);
  border-radius: 20px;
  padding: 20px;
  background-color: rgb(93, 151, 199);
  box-shadow: 0 12px 15px 0 rgba(0, 0, 0, 0.25);
  width: 50%;
  max-width: 500px;
  opacity: 0;
  pointer-events: none;
}

.modal.visible {
  opacity: 1;
  pointer-events: auto;
}

.modal__close-icon {
  display: block;
  position: absolute;
  top: -25px;
  right: -25px;
}

.modal__close-icon img {
  width: 35px;
  height: 35px;
}

.form-text {
  text-align: center;
  color: #fff;
  font-size: 18px;
}

.form-item {
  margin-top: 20px;
}

.form-item label {
  color: #fff;
  line-height: 1.2;
  cursor: pointer;
}

input[type="number"],
input[type="text"] {
  padding: 5px;
}

input[type="text"] {
  width: 100%;
  height: 20px;
  margin-top: 5px;
}

input[type="number"] {
  width: 100px;
  height: 20px;
  margin-top: 5px;
}

input[type="submit"] {
  cursor: pointer;
  width: 200px;
  border: none;
  max-width: 100%;
  padding: 10px;
  display: flex;
  justify-content: center;
  margin: 30px auto 0;
  background-color: #fff;
  transition: background-color 0.3s;
}

input[type="submit"]:hover {
  background-color: #333;
  color: #fff;
  transition: background-color 0.3s;
}

              
            
!

JS

              
                const modalBtn = document.getElementById("js-modal-btn");
const modal = document.getElementById("js-modal");
const requestBtn = document.getElementById("js-request-btn");
const ul = document.getElementById("js-ul");
const modalCloseIcon = document.getElementById('js-modal-close-icon');

function addLoading() {
  const wrapper = document.getElementById("js-wrapper");
  const loading = document.createElement("img");
  loading.src = "./img/loading-circle.gif";
  loading.id = "loading";
  wrapper.appendChild(loading);
}

function removeLoading() {
  const loading = document.getElementById("loading");
  loading.remove();
}

async function fetchErrorHandling(response) {
  if (response.ok) {
    return await response.json();
  } else {
    throw new Error("サーバーエラーが発生しました");
  }
}

async function getJsonOrError() {
  const response = await fetch(
    "https://jsondata.okiba.me/v1/json/fR9k5211007080400"
  );
  const json = await fetchErrorHandling(response);
  return json;
}

function createLists({ data }) {
  const frag = document.createDocumentFragment();
  data.forEach(value => {
    const { a, img, alt, text } = value;
    const li = document.createElement("li");
    const anchor = document.createElement("a");
    const image = document.createElement("img");

    anchor.href = `/${a}.html`;
    image.src = img;
    image.alt = alt;

    frag.appendChild(li).appendChild(anchor).appendChild(image);
    anchor.insertAdjacentHTML("beforeend", text);
  });
  ul.appendChild(frag);
}

async function tryGetData() {
  addLoading();
  try {
    return await getJsonOrError();
  } catch (error) {
    ul.replaceWith(error);
  } finally {
    removeLoading();
  }
}

async function tryCreate() {
  try {
    const responseData = await tryGetData();
    if (responseData.data) {
      createLists(responseData);
    } else {
      throw new Error("適切なデータが見つかりませんでした");
    }
  } catch (error) {
    ul.replaceWith(error);
  }
}

modalBtn.addEventListener("click", (e) => {
  e.target.style.display = "none";
  modal.classList.add("visible");
});

requestBtn.addEventListener("click", (e) => {
  const inputName = document.getElementById("name").value;
  const inputNumber = document.getElementById("number").value;
  e.preventDefault();

  const trimInputName = inputName.trim();

  if (trimInputName.length === 0 || inputNumber === "") {
    alert("Name or number not entered properly.Please confirm.");
  } else {
    console.log(`Name: ${trimInputName}, Number: ${inputNumber}`);
    tryCreate();
    modal.classList.remove("visible");
  }
});

modalCloseIcon.addEventListener('click', () => {
  modal.classList.remove("visible");
  modalBtn.style.display = "block";
});

              
            
!
999px

Console