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

              
                <div id="app">
  <section>
    <div class="flex items-center mb-6">
      <h1 class="text-4xl font-thin text-gray-400 mr-10">5s timer</h1>
      <button class="rounded bg-blue-600 hover:bg-blue-500 text-white px-4 py-2 mr-3 text-sm" @click="startTimer">
        Start
      </button>
      <button class="rounded bg-gray-300 hover:bg-gray-200 px-4 py-2 mr-8 text-sm" @click="resetTimer">
        Reset
      </button>
    </div>
    
    <div class="flex items-center text-xl font-mono mb-10">
      <div class="mr-3 text-gray-600">
        {{ milliseconds }}ms
      </div>
      <div class="mr-3 text-gray-300">
        >
      </div>
      <div class="font-bold text-2xl w-12 mr-8">
        {{ seconds }}s
      </div>
      <div class="w-48 h-4 border-2 border-green-500 mr-8">
        <div class="h-full bg-green-500 float-right" :style="{ width: `${percent}%` }"></div>
      </div>
      <div
        class="rounded text-sm bg-gray-500 text-white text-center py-1 w-20"
        :class="{
          'bg-gray-500': !countdownInterval,
          'bg-green-500': countdownInterval,
        }"
      >
        {{ countdownInterval ? 'running' : 'paused' }}
      </div>
    </div>
    
    <div class="flex items-center text-xl font-mono mb-10">
      <div class="mr-3 text-gray-600">
        {{ milliseconds }}ms
      </div>
      <div class="mr-3 text-gray-300">
        >
      </div>
      <div class="font-bold text-2xl w-12 mr-8">
        {{ seconds }}.{{ secondDecimals }}s
      </div>
      <div class="w-48 h-4 border-2 border-green-500 mr-8">
        <div class="h-full bg-green-500 float-right" :style="{ width: `${percent}%` }"></div>
      </div>
      <div
        class="rounded text-sm bg-gray-500 text-white text-center py-1 w-20"
        :class="{
          'bg-gray-500': !countdownInterval,
          'bg-green-500': countdownInterval,
        }"
      >
        {{ countdownInterval ? 'running' : 'paused' }}
      </div>
    </div>
    
    <div class="flex items-center text-xl font-mono">
      <div class="mr-3 text-gray-600">
        {{ fakeMilliseconds }}ms
      </div>
      <div class="mr-3 text-gray-300">
        >
      </div>
      <div class="font-bold text-2xl w-12 mr-8">
        {{ fakeSeconds }}s
      </div>
      <div class="w-48 h-4 border-2 border-green-500 mr-8">
        <div class="h-full bg-green-500 float-right" :style="{ width: `${percent}%` }"></div>
      </div>
      <div
        class="rounded text-sm bg-gray-500 text-white text-center py-1 w-20"
        :class="{
          'bg-gray-500': !countdownInterval,
          'bg-green-500': countdownInterval,
        }"
      >
        {{ countdownInterval ? 'running' : 'paused' }}
      </div>
    </div>
  </section>
</div>
              
            
!

CSS

              
                
              
            
!

JS

              
                /*
 * Instantiate Vue App
 */
new Vue({
  el: '#app',
  data() {
    return {
      countdownInterval: null,
      time: 5000,
      fakeTime: 5500,
    }
  },
  computed: {
    percent () {
      return Math.floor((this.time / 5000) * 100)
    },
    milliseconds () {
      return _.padStart(this.time, 4, '0');
    },
    seconds () {
      return Math.floor(this.time / 1000)
    },
    secondDecimals () {
      return Math.floor((this.time % 1000) / 100)
    },
    fakeMilliseconds () {
      return _.padStart(this.fakeTime, 4, '0');
    },
    fakeSeconds () {
      return Math.floor(this.fakeTime / 1000)
    },
  },
  methods: {
    resetTimer () {
      this.time = 5000
      this.fakeTime = 5500
      clearTimeout(this.countdownInterval)
      this.countdownInterval = null
    },
    startTimer () {
      this.countdownInterval = setInterval(() => {
        if (this.time <= 0) {
          clearTimeout(this.countdownInterval)
          this.countdownInterval = null
        } else {
          this.time -=  10
          this.fakeTime -= 10
        }
      }, 10);
    },
  },
})
              
            
!
999px

Console