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

              
                <h3>单次点击</h3>
<h5>通过animationend实现</h5>
<button class="button button1" id="btn1" oneclick="fn()">按钮1</button>
<h5>纯css实现,需使用onmousedown</h5>
<button class="button button2" onmousedown="fn()">按钮2</button>


              
            
!

CSS

              
                .button1{
  animation: once .01s paused forwards;
}
.button1:hover:active{
  animation-play-state:running;
}
@keyframes once {
  to{
    opacity:.8;
  }
}

.button2{
  animation: once2 10s forwards;
}
.button2:hover:active{
      animation-delay:0s
}
@keyframes once2 {
  1%{
    opacity:.5;
    pointer-events:none;
    user-select:none;
    background:red
  }
  100%{
    opacity:.5;
    pointer-events:all;
    user-select:none;
    background:none
  }
}
              
            
!

JS

              
                
function fn(ev){
  console.log('5555555')
  //alert('我只能点一次')
}



document.querySelectorAll('.button').forEach(function(el){
  el.addEventListener('animationend',function(){
    // 创建并分发事件
    var event = new CustomEvent("oneclick");
    el.dispatchEvent(event);
    eval(''+this.getAttribute('oneclick')+'');
    if(el['oneclick']){
       el['oneclick'](event);
    }
  })
})

              
            
!
999px

Console