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

              
                <!-- Mobile container -->
<main class="container">
    <!-- Progress bar -->
    <div class="progress"></div>
    <!-- Countdown counter -->
    <div class="counter">1</div>
    <!-- Button to toggle countdown -->
    <button class="button">Toggle</button>
</main>
              
            
!

CSS

              
                :root {
  // CSS variable to update progress
  --progress: 100;
}

*, *:before, *:after {
  box-sizing: border-box;
}

body {
  overflow: hidden;

  // Decorative background
  &:before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    border-left: 50vw solid #FF6E6E;
    border-right: 50vw solid #FF6E6E;
    border-top: 50vh solid #354051;
    border-bottom: 50vh solid #354051;
    z-index: -1;
  }
}

// Mobile container
.container {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 340px;
  height: 540px;
  background-color: #354051;
  box-shadow: 0 0 100px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%);
  overflow: hidden;

  // Header bar, just a aesthetic detail
  &:before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 25px;
    background-color: rgba(0, 0, 0, 0.2);
    z-index: 3;
  }
}

// Container for progress bar and expansive button
.progress {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;

  // Expansive button, initially the red button we can see
  &:before {
    content: '';
    position: absolute;
    left: calc(50% - 30px);
    bottom: 50px;
    width: 60px;
    height: 60px;
    background-color: #FF6E6E;
    border-radius: 100%;
    transform: scale(1);
    transition: 0.8s transform;
  }

  // Progress bar
  &:after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 50px 0 50px rgba(0, 0, 0, 0.1);
    transform: translateY(calc(var(--progress) * 1%)); // Set translation using `--progress`
    transition: 0.95s transform cubic-bezier(0.175, 0.885, 0.320, 1.275); // easeOutBack
  }
}

// Countdown counter, initially hidden
.counter {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  font-size: 100px;
  font-family: 'Roboto Mono', monospace;
  color: #FFFFFF;
  pointer-events: none;
  opacity: 0;
  z-index: 3;
  transition: 0.5s opacity;
}

// Button to toggle countdown
.button {
  position: absolute;
  left: calc(50% - 30px);
  bottom: 50px;
  width: 60px;
  height: 60px;
  padding: 0;
  color: transparent;
  background-color: transparent;
  outline: none;
  border: none;
  border-radius: 100%;
  text-indent: -999px; // Hiding text
  z-index: 2;
  cursor: pointer;

  // Gray button to stop countdown
  &:before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    border-radius: 100%;
    background-color: transparent;
    transform: scale(0);
    transition: 0.5s 0.5s transform, 0.5s 0.5s background-color;
  }

  // Element for the expansive shadow effect on click
  &:after {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    border-radius: 100%;
    opacity: 0;
    box-shadow: inset 0 0 0 20px rgba(255, 255, 255, 1);
    transition: 0s;
    pointer-events: none;
    z-index: -1;
  }
}

// Styles for countdown running
.container--running {

  // Expand the red button to cover the container entirely
  // Using the `easeInBack` easing to get a nice effect
  .progress:before {
    transform: scale(17);
    transition: 0.8s transform cubic-bezier(0.600, -0.280, 0.735, 0.045); // easeInBack
  }

  // Show the counter
  .counter {
    opacity: 1;
    transition: 1s opacity;
  }

  .button {

    // Show the gray circle (stop button)
    &:before {
      background-color: #354051;
      transform: scale(1);
      transition: 0.5s 0.5s transform, 0.5s 0.5s background-color;
    }

    // Scale the element and reduce the shadow, getting the desired effect
    &:after {
      opacity: 1;
      transform: scale(2.5);
      box-shadow: inset 0 0 0 0 rgba(255, 255, 255, 0);
      transition: all 0.8s, opacity 0.3s;
    }
  }
}


// _ms-countdown-timer.scss

// Slider dimmensions
$ms-container-width: 340px;
$ms-slide-width: 125px;
$ms-slide-height: 540px;

// Slider container
.ms-container {
  position: relative;
  top: 50%;
  width: $ms-container-width;
  max-width: 100%;
  margin: 0 auto;
  overflow: hidden;
  transform: translateY(-50%);

  // Gradients to hide the adjacent numbers smoothly
  &:before, &:after {
    content: '';
    position: absolute;
    top: 0;
    width: 80px;
    height: 100%;
    z-index: 1;
    pointer-events: none;
  }
  &:before {
    left: 0;
    background-image: linear-gradient(to right, rgba(53, 64, 81, 1) 25%, rgba(53, 64, 81, 0));
  }
  &:after {
    right: 0;
    background-image: linear-gradient(to left, rgba(53, 64, 81, 1) 25%, rgba(53, 64, 81, 0));
  }
}

// Slider track
.ms-track {
  position: relative;
  left: calc(50% - #{$ms-slide-width / 2}); // Centering
  white-space: nowrap;
  font-size: 0;
  list-style: none;
  padding: 0;
  margin: 0;
  will-change: transform;
}

// Slides
.ms-slide {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: $ms-slide-width;
  height: $ms-slide-height;
  font-size: 100px;
  font-family: 'Roboto Mono', monospace;
  color: #FFFFFF;
  cursor: default;
  user-select: none;
  will-change: transform;
}

              
            
!

JS

              
                (function() {

    // Variables to use later
    var root = document.documentElement;
    var container = document.querySelector('.container');
    var button = document.querySelector('.button');
    var counter = document.querySelector('.counter');
    var running = false;
    var timer = null;
    var seconds = 0;
    var secondsInitial = 0;

    // Initializing the slider
    var ms = new MomentumSlider({
        el: container,  // HTML element to append the slider
        range: [1, 60], // Generar los elementos del slider usando el rango de números definido
        loop: 2,        // Hacer infinito el slider, añadiendo 2 elementos extra en cada extremo
        style: {
            // Estilos para interpolar
            // El primer valor corresponde a los elementos adyacentes
            // El segundo valor corresponde al elemento actual
            transform: [{scale: [0.4, 1]}],
            opacity: [0.3, 1]
        }
    });

    // Simple toggle functionality
    button.addEventListener('click', function () {
        if (running) {
            stop();
        } else {
            start();
        }
        running = !running;
    });

    // Start the countdown
    function start() {
        // Disable the slider during countdown
        ms.disable();
        // Get current slide index, and set initial values
        seconds = ms.getCurrentIndex() + 1;
        counter.innerText = secondsInitial = seconds;
        root.style.setProperty('--progress', 0);
        // Add class to trigger CSS transitions for `running` state
        container.classList.add('container--running');
        // Set interval to update the component every second
        timer = setInterval(function () {
            // Update values
            counter.innerText = --seconds;
            root.style.setProperty('--progress', (secondsInitial - seconds) / secondsInitial * 100);
            // Stop countdown if it's finished
            if (!seconds) {
                stop();
                running = false;
            }
        }, 1000);
    }

    // Stop the countdown
    function stop() {
        // Enable slider
        ms.enable();
        // Clear interval
        clearInterval(timer);
        // Reset progress
        root.style.setProperty('--progress', 100);
        // Remove `running` state
        container.classList.remove('container--running');
    }

})();

              
            
!
999px

Console