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

              
                <div class="center-center">
  <button>Share<i class="fas fa-share-alt"></i></button>
  <p class="result"></p>
</div>

              
            
!

CSS

              
                // The style of button is modified from https://codepen.io/ayoisaiah/pen/YbNazJ

html, body {
  background-color: #dedede;
  height: 100%;
}

.center-center {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  flex-direction: column;
}
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: auto;
  padding: 8px 30px;
  color: #777;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: 2px;
  text-transform: capitalize;
  text-decoration: none;
  white-space: nowrap;
  border-radius: 4px;
  border: 1px solid #ddd;
  cursor: pointer;
  background-color: white;
}

button:hover {
  border-color: #cdd;
}

.fa-share-alt {
  padding-left: 5px;
}



              
            
!

JS

              
                // 選擇和 DOM 有關的元素
const btn = document.querySelector("button");
const result = document.querySelector(".result");

// 當使用者點擊分享時要帶入的資訊
const shareData = {
  url: "https://pjchender.blogspot.com", // 要分享的 URL
  title: "PJCHENder 那些沒告訴你的小細節", // 要分享的標題
  text: "好多眉眉角角啊" // 要分享的文字內容
};

// 當使用者點擊按鈕時
btn.addEventListener("click", async () => {
  try {
    // 使用 Web Share API
    await navigator.share(shareData);
    result.textContent = "感謝你的的分享";
  } catch (err) {
    // 使用者拒絕分享或發生錯誤
    const { name, message } = err;
    if (name === "AbortError") {
      result.textContent = "您已取消分享此訊息";
    } else {
      result.textContent = err;
      console.log("發生錯誤", err);
    }
  }
});

              
            
!
999px

Console