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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <pre>
<button onclick="onClick()" id="active">クリックして実行</button>

<button onclick="reset()" id="reset">リセット</button>

<p id="txt"></p>
</pre>
              
            
!

CSS

              
                
#txt {
  display: inline-block;
}

#txt::after {
  content: '';
  display: block;
  width: 0;
  height: 2px;
  background-color: #f00;
  transition: width 500ms;
}

#txt.add_line::after {
    width: 100%;
}
              
            
!

JS

              
                // ----------------------------------------
// Promiseを理解する
// その2
// 
// ■ 逐次処理を実行する
// ----------------------------------------

let p = document.getElementById('txt');

// Promiseオブジェクトを返す関数
// ------------------------------------------
// 成功 ---> resolve
// 失敗 ---> reject

// 'レッカスグルーヴ' を追加
function addRecusGroove(msg) {
  return new Promise(function(resolve, reject) {
    setTimeout(function() {
      addText(msg, 'レッカスグルーヴ');
      resolve(msg + 'レッカスグルーヴ');
    }, 500);
  });
}

// 'クリエイターズブログ' を追加
function addCreatorsBlog(msg) {
  return new Promise(function(resolve, reject) {
    setTimeout(function() {
      addText(msg, 'クリエイターズブログ');
      resolve();
    }, 500);
  });
}

// テキストをappendする関数
function addText(msg, text) {
  p.textContent = msg + text;
}

// 下線を引く
function underLine() {
  setTimeout(function() {
    p.classList.add('add_line');
  }, 500)
}
 
// ボタンクリックで実行
// ------------------------------------------
function onClick() {
  document.getElementById('active').disabled = true;
  let promise = new Promise(function(resolve, reject) {
    addText('', '山口');
    // 成功
    resolve('山口');
    // 失敗
    reject('Error...');
  });
  
  promise
    .then(function(msg) {
      addRecusGroove(msg)
      .then(function(msg) {
        addCreatorsBlog(msg)
        .then(function() {
          underLine()
        });
      });
    });
}

// リセット
// -----------------------------------------------
function reset() {
  document.getElementById('active').disabled = false;
  p.textContent = '';
  p.classList.remove('add_line');
}
              
            
!
999px

Console