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

              
                <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<div class="modal"></div>
<div class="dialog">
  <div class="title">標題</div>
  <div class="content">
    <div>這裡可以放入任何內容,無論是純文字或html版型都可以。</div>
    <div>此範例的CSS看起來略微複雜,但大部份只是樣式設定,可以隨個人喜好調整、增加、刪除。</div>
    <div>與動畫效果相關性較高的部份都有加上註解,希望能幫助到你。</div>
  </div>
  <div class="buttons">			
    <div class="cancelBtn">取消</div>
    <div class="okBtn">確定</div>
  </div>
</div>

<button class="showDialogBtn" style="margin: 30px;">show dialog</button>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}
body {
  margin: 0;
  padding: 0;
}

.modal {
  position: absolute;	
  z-index: 10;		
  display: none;
  width: 100%;
  height: 100%;
  background: #6a6a6aa6;			
}

.dialog {		
  position: absolute;
  z-index: 11;
  /* 將對話框水平置中。 */
  left: 50%;	
  transform: translate(-50%, 0%);			
  top: -10px; /* 設定對話框的起始位置。 對話框滑動的距離與時間會影響淡入效果,可以自行嘗試調整。 */
  opacity: 0; /* 將對話框設為透明。 */
  display: none; /* 隱藏對話框。 */
  width: 90%; /* 對話框寬度。 */
  background: white;
  box-shadow: 2px 2px 8px 1px rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  line-height: 1.7em;
}

.title {
  text-align: center;
  padding: 8px;
  font-size: 20px;
  background: #1f7038ad;    		
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  color: white;
  border: 1px #f2e6e6 solid;
  box-shadow: 0px 2px 8px 1px rgb(0 0 0 / 15%);
}

.content {
  padding: 4px 8px;
}

.buttons {
  /* 加上這兩個CSS,可以讓button移動到對話框下方。 */
  /*position: absolute;
  right: 0px;
  */
  text-align: right;
  padding: 8px 14px;
}

.okBtn {
  display: inline-block;
  background: #092b68b3;
  color: #ffffffeb;		    
  border-radius: 8px;
  border: 1px solid white;
  padding: 4px 8px;
  cursor: pointer;
}

.cancelBtn {
  display: inline-block;
  background: #e90202ad;
  color: #ffffffeb;		    
  border-radius: 8px;
  border: 1px solid white;
  padding: 4px 8px;
  cursor: pointer;  
}
              
            
!

JS

              
                $(".showDialogBtn").click( function () {
  $(".modal").css("display", "block"); // 顯示modal,遮住畫面背景。
  $(".dialog").css("display", "block"); // 顯示dialog。
  
  $(".dialog").animate({			   
    opacity: '1',
    top: '50px' // 決定對話框要滑到哪個位置停止。		   
  }, 550);
});

$(".cancelBtn").click( function () {
  $(".dialog").animate({			   
    opacity: '0',
    top: '-50px' // 需與CSS設定的起始位置相同,以保證下次彈出視窗的效果相同。			   
  }, 350, function () {
    // 此區塊為callback function,會在動畫結束時被呼叫。
    $(".modal").css("display", "none"); // 隱藏modal。
    $(".dialog").css("display", "none"); // 隱藏dialog。
  });
});	
              
            
!
999px

Console