123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <p>
  Inspiration from <a href="https://uimovement.com/ui/5243/toggle/" target="blank"> this UI movement submission</a>
</p>

<div id="widget" class="center">
  <label for="toggleControl">Click the sleepy face!</label>
  <div @click="toggle"
       @keyup.space="toggle"
       @keyup.enter="toggle"
       :aria-checked="isChecked" 
       class="toggle-container" 
       role="checkbox" 
       tabindex="0" id="toggleControl">
    
    <!-- backgrounds active -->
    <div class="toggle-color-bg"></div>
    <!-- background inactive -->
    <div :class="{'fade': active}" class="toggle-gray-bg"></div>
    
    <!-- ball -->
    <div :class="{'active': active}" class="ball-face">
      <div class="faces-container">
        <div :class="{'active': active}" class="faces-together">
          <!-- happy face svg -->
          <svg class="happy-face" viewBox="0 0 59 51" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
            <g id="Canvas" transform="translate(1337 -940)">
            <g id="happy face">
            <g id="Ellipse">
            <use xlink:href="#path0_fill" transform="translate(-1337 940)" fill="#8A8B8A"/>
            </g>
            <g id="Ellipse">
            <use xlink:href="#path0_fill" transform="translate(-1290 940)" fill="#8A8B8A"/>
            </g>
            <g id="Rectangle" filter="url(#filter0_i)">
            <use xlink:href="#path1_fill" transform="translate(-1337 971)" fill="#C4C4C4"/>
            </g>
            </g>
            </g>
            <defs>
            <filter id="filter0_i" filterUnits="userSpaceOnUse" x="-1337" y="971" width="63" height="24" color-interpolation-filters="sRGB">
            <feFlood flood-opacity="0" result="BackgroundImageFix"/>
            <feBlend mode="normal" in="SourceGraphic" in2="BackgroundImageFix" result="shape"/>
            <feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 0" result="hardAlpha"/>
            <feOffset dx="4" dy="4"/>
            <feGaussianBlur stdDeviation="6"/>
            <feComposite in2="hardAlpha" operator="arithmetic" k2="-1" k3="1"/>
            <feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0"/>
            <feBlend mode="normal" in2="shape" result="effect1_innerShadow"/>
            </filter>
            <path id="path0_fill" d="M 12 6C 12 9.31371 9.31371 12 6 12C 2.68629 12 0 9.31371 0 6C 0 2.68629 2.68629 0 6 0C 9.31371 0 12 2.68629 12 6Z"/>
            <path id="path1_fill" d="M 0 2.22222C 0 0.994923 0.994923 0 2.22222 0L 56.7778 0C 58.0051 0 59 0.994923 59 2.22222L 59 2.22222C 59 12.0406 51.0406 20 41.2222 20L 17.7778 20C 7.95938 20 0 12.0406 0 2.22222L 0 2.22222Z"/>
            </defs>
          </svg>

          <!-- sleepy face svg -->
          <svg class="sleepy-face" viewBox="0 0 51 30" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
            <g id="Canvas" transform="translate(1177 -946)">
            <g id="sleepy face">
            <g id="Vector">
            <use xlink:href="#sleepy_path0_fill" transform="translate(-1176.44 946.786)" fill="#8A8B8A"/>
            <use xlink:href="#sleepy_path1_stroke" transform="translate(-1176.44 946.786)" fill="#8A8B8A"/>
            </g>
            <g id="Vector">
            <use xlink:href="#sleepy_path0_fill" transform="translate(-1142 947)" fill="#8A8B8A"/>
            <use xlink:href="#sleepy_path1_stroke" transform="translate(-1142 947)" fill="#8A8B8A"/>
            </g>
            <g id="Vector 2">
            <use xlink:href="#sleepy_path2_fill" transform="translate(-1159.55 969.5)" fill="#8A8B8A"/>
            <use xlink:href="#sleepy_path3_stroke" transform="translate(-1159.55 969.5)" fill="#8A8B8A"/>
            </g>
            </g>
            </g>
            <defs>
            <path id="sleepy_path0_fill" d="M 12.4433 4.71365C 6.94326 8.71367 2.27664 4.88032 0.443304 2.71365C -0.556641 0.713687 -0.0566955 -0.486341 3.9433 0.713687C 8.9433 2.21372 9.94334 1.21371 12.4433 0.213711C 14.9433 -0.786289 16.3213 1.8933 12.4433 4.71365Z"/>
            <path id="sleepy_path1_stroke" d="M 0.443304 2.71365L -0.00391265 2.93725L 0.0228929 2.99086L 0.0616111 3.03662L 0.443304 2.71365ZM 12.4433 4.71365L 12.7374 5.11802L 12.4433 4.71365ZM 12.4433 0.213711L 12.2576 -0.250526L 12.2576 -0.250526L 12.4433 0.213711ZM 3.9433 0.713687L 4.08698 0.234775L 4.08698 0.234775L 3.9433 0.713687ZM 0.0616111 3.03662C 1.00963 4.157 2.70413 5.72844 4.90311 6.49809C 7.13392 7.27888 9.84841 7.21909 12.7374 5.11802L 12.1492 4.30928C 9.53816 6.20824 7.16932 6.23178 5.23347 5.55423C 3.26579 4.86554 1.71032 3.43697 0.824997 2.39068L 0.0616111 3.03662ZM 12.7374 5.11802C 13.746 4.38451 14.4399 3.64099 14.8603 2.93621C 15.2786 2.23493 15.4422 1.54173 15.3261 0.9368C 15.2065 0.313937 14.7988 -0.156382 14.216 -0.370882C 13.6493 -0.579506 12.9629 -0.532653 12.2576 -0.250526L 12.629 0.677949C 13.1737 0.460076 13.5971 0.466877 13.8706 0.567562C 14.1282 0.66237 14.2913 0.85072 14.344 1.1253C 14.4001 1.41781 14.3374 1.86082 14.0015 2.42394C 13.6677 2.98356 13.0796 3.63262 12.1492 4.30928L 12.7374 5.11802ZM 12.2576 -0.250526C 10.9348 0.278589 10.1663 0.731519 9.05284 0.907332C 7.97127 1.0781 6.55427 0.974979 4.08698 0.234775L 3.79963 1.1926C 6.33234 1.95243 7.91536 2.09932 9.2088 1.89509C 10.4703 1.69591 11.4518 1.14883 12.629 0.677949L 12.2576 -0.250526ZM 4.08698 0.234775C 3.06772 -0.0710107 2.24174 -0.233411 1.58935 -0.260882C 0.949793 -0.287813 0.395764 -0.188595 0.00597538 0.12324C -0.414433 0.45957 -0.532592 0.948393 -0.492446 1.43019C -0.453489 1.8977 -0.265425 2.41421 -0.00391265 2.93725L 0.890521 2.49005C 0.652061 2.01311 0.527639 1.62963 0.504101 1.34715C 0.481752 1.07895 0.55109 0.967773 0.630675 0.904105C 0.740879 0.815941 0.99934 0.715159 1.54728 0.738232C 2.08237 0.760764 2.81889 0.898371 3.79963 1.1926L 4.08698 0.234775Z"/>
            <path id="sleepy_path2_fill" d="M 0.552112 2.99999C -1.34367 0.156396 2.05212 0 4.55208 0C 4.71876 0.166652 5.55212 1.47633e-05 8.55212 0C 12.0877 -1.73987e-05 10.5521 3.5 8.55212 4.49996C 6.55212 5.49991 2.55216 5.99997 0.552112 2.99999Z"/>
            <path id="sleepy_path3_stroke" d="M 4.55208 0L 4.9056 -0.353584L 4.75916 -0.5L 4.55208 -0.5L 4.55208 0ZM 0.552112 2.99999L 0.968133 2.72263L 0.968133 2.72263L 0.552112 2.99999ZM 8.55212 0L 8.55212 -0.5L 8.55212 0ZM 4.55208 -0.5C 3.92436 -0.5 3.22426 -0.490334 2.55987 -0.429016C 1.90232 -0.36833 1.24138 -0.254105 0.707429 -0.0262233C 0.17342 0.201682 -0.322538 0.585085 -0.462649 1.22459C -0.597099 1.83826 -0.364431 2.52658 0.136091 3.27734L 0.968133 2.72263C 0.520763 2.05159 0.466986 1.65402 0.514182 1.43861C 0.555717 1.24903 0.709495 1.06016 1.09996 0.893516C 1.49047 0.726851 2.02874 0.624253 2.65177 0.566752C 3.26796 0.509883 3.92982 0.5 4.55208 0.5L 4.55208 -0.5ZM 0.136091 3.27734C 1.24066 4.93415 2.89847 5.61389 4.51062 5.74822C 6.10978 5.88147 7.70098 5.48452 8.77572 4.94717L 8.32852 4.05274C 7.40327 4.51535 5.99449 4.8684 4.59366 4.75168C 3.20581 4.63603 1.86361 4.06581 0.968133 2.72263L 0.136091 3.27734ZM 8.77572 4.94717C 9.35226 4.65892 9.87822 4.20083 10.2855 3.68475C 10.6916 3.17031 11.0043 2.56697 11.119 1.96924C 11.2344 1.36812 11.1551 0.717421 10.6898 0.220683C 10.2346 -0.265349 9.505 -0.500005 8.55212 -0.5L 8.55212 0.5C 9.36701 0.499996 9.7713 0.702836 9.96 0.904301C 10.1387 1.09506 10.2135 1.38186 10.1369 1.78074C 10.0597 2.183 9.83447 2.64215 9.50057 3.06521C 9.16797 3.48662 8.75198 3.84102 8.32852 4.05274L 8.77572 4.94717ZM 8.55212 -0.5C 7.04205 -0.499993 6.07507 -0.457981 5.47238 -0.437203C 5.16449 -0.426588 4.97421 -0.422558 4.85181 -0.429C 4.79098 -0.432202 4.77063 -0.437078 4.77252 -0.436596C 4.7726 -0.436574 4.83796 -0.421216 4.9056 -0.353584L 4.19856 0.353584C 4.30787 0.462879 4.43573 0.509484 4.52501 0.532292C 4.6161 0.555559 4.71163 0.565006 4.79925 0.569617C 4.97373 0.578801 5.21055 0.572418 5.50683 0.562203C 6.1125 0.541322 7.06219 0.500007 8.55212 0.5L 8.55212 -0.5Z"/>
            </defs>
            </svg>    
        </div>
              
      </div>
    </div>
  </div>
</div>
            
          
!
            
              .center {
  margin-left: calc(50% - 75px);
  margin-top: 50px;
}
.toggle-container {
  position: relative;
  cursor: pointer;
  margin: 20px 0;
  outline:0;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
.toggle-gray-bg {
  background: #D4CFD0;
  width: 150px;
  height: 70px;
  margin-top: -70px;
  border-radius: 50px;
  transition: opacity .4s;
}
.toggle-gray-bg.fade {
  opacity: 0;
}
.toggle-color-bg {
  background: linear-gradient(to right, #E992EE, #EB92B3);
  width: 150px;
  height: 70px;
  border-radius: 50px;
}
.ball-face {
  position: absolute;
  overflow: hidden;
  left: 7px;
  top: 7px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  transition: left .4s ease-in-out;
  background: linear-gradient(45deg, #c6c6c6 0%,#ffffff 60%);
  box-shadow: -1px 3px 8px 0px rgba(0,0,0,0.2);
}
.ball-face.active {
  left: 87px;
}
.faces-container {
  position: relative;
}
.faces-together {
  position: absolute;  
  transition: left .4s ease-in-out;
  left: 0;
}
.faces-together.active {
  left: 140px;
}
.happy-face {
  position: absolute;
  top: 18px;  
  left: -120px;
  width: 25px;
}
.sleepy-face {
  position: absolute;
  top: 27px;  
  left: 10px;
  width: 25px;
}
            
          
!
            
              var widget = new Vue({
  el: '#widget',
  data: {
    active: false
  },
  methods: {
    toggle () {
      this.active = !this.active
    }
  },
  computed: {
    isChecked () {
      return this.active ? 'true' : 'false'
    }
  }
})
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console