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.

            
              .pac-input
  input(type='password', value='chomprulz')
  a.pac-input__pac
  a.pac-input__ghost
    .pac-input__ghost-eyes
  .pac-input__cloak
            
          
!
            
              *
  box-sizing border-box


$bg = #111
$input = #aaa
$pac = yellow
$border = blue
$entitySize = 30px
$inputWidth = 300px
$inputHeight = 50px
$fontSize = 24px
$chompSpeed = .25s
$entityMargin = ($inputHeight - $entitySize) / 2px

html
body
  background $bg
  display flex
  align-items center
  justify-content center
  height 100vh
  width 100vw
  font-family 'Arial', sans-serif

.pac-input
  position relative
  overflow hidden
  border 6px solid $border
  border-radius 8px

  & > input
    border 0
    border-radius 0
    font-size $fontSize
    line-height $fontSize
    padding 6px 45px 6px 12px
    letter-spacing 1px
    width $inputWidth
    height $inputHeight
    background $input
    background-image none !important

  &__cloak
    background-color $input
    width 100%
    height $entitySize
    position absolute
    top $entityMargin
    left 100%
    margin-left -(($entitySize / 2px) + $entityMargin)

  &__ghost
    cursor pointer
    height $entitySize
    width 100%
    position absolute
    right 105%
    top $entityMargin
    width $entitySize
    border-radius 100% 100% 0 0
    position absolute
    z-index 1
    clip-path polygon(15% 100%, 0 85%, 0 0, 100% 0, 100% 85%, 85% 100%, 66% 85%, 50% 100%, 30% 85%)
    -webkit-clip-path polygon(15% 100%, 0 85%, 0 0, 100% 0, 100% 85%, 85% 100%, 66% 85%, 50% 100%, 30% 85%)

    &-eyes
      height 6px
      width 20px
      position absolute
      top 8px
      left 5px


      &:before
      &:after
        border-radius 100%
        content ''
        height 6px
        width 6px
        background radial-gradient(circle at 30% 60%, blue 0, blue 25%, white 25%, white 100%)
        position absolute

      &:after
        left 8px

  &__pac
    cursor pointer
    position absolute
    top $entityMargin
    right $entityMargin
    height $entitySize
    width $entitySize
    z-index 1

    &--chomping
      &:before
        animation-name chomp--1
      &:after
        animation-name chomp--2


    &:before
    &:after
      content ''
      position absolute
      left 0
      border-radius 100%
      border ($entitySize / 2px) solid $pac
      transform-origin center center
      animation-duration $chompSpeed
      animation-timing-function linear
      animation-iteration-count infinite

    &:before
      border-left-color transparent
      border-bottom-color transparent

    &:after
      border-top-color transparent
      border-right-color transparent
      transform rotate(-90deg)

@keyframes chomp--1
  0%, 100%
    transform rotate(0deg)
  50%
    transform rotate(-45deg)

@keyframes chomp--2
  0%, 100%
    transform rotate(-90deg)
  50%
    transform rotate(-45deg)
            
          
!
            
              const pacInput = document.querySelector('.pac-input')
const pac = pacInput.querySelector('.pac-input__pac')
const ghost = pacInput.querySelector('.pac-input__ghost')
const ghostEyes = ghost.querySelector('.pac-input__ghost-eyes')
const input = pacInput.querySelector('input')
const cloak = pacInput.querySelector('.pac-input__cloak')
const inputBounds = input.getBoundingClientRect()
const pacBounds = pac.getBoundingClientRect()

const COLORS = {
  INPUT: '#aaa',
  BG: '#111',
  GHOST: [
    'rgb(253, 177, 71)',
    'rgb(63, 219, 192)',
    'rgb(251, 179, 202)',
    'rgb(248, 34, 17)',
  ]
}
const DURATIONS = {
  ENV: 0.15,
  CHOMP: 1,
  GHOST: 1,
  EYES: 0.5,
}

const hidePassword = () => {
  const ghostTimeline = new TimelineMax()
  ghostTimeline
    .add(
      TweenMax.to(ghost, DURATIONS.EYES, {
        right: '105%',
        ease: Power0.easeNone,
        onStart: () => {
          ghost.style.backgroundColor = COLORS.INPUT
        },
        onComplete: () => {
          ghost.style.backgroundColor = 'green'
        },
      }),
      0
    )
    .add(
      TweenMax.to(cloak, DURATIONS.EYES, {
        onComplete: () => {
          input.setAttribute('type', 'password')
        },
        left: -5,
        ease: Power0.easeNone,
      }),
      0
    )
    .add(
      TweenMax.to(pac, 0, {
        right: 10,
        scale: 0,
      })
    )
    .add(
      TweenMax.to(cloak, DURATIONS.ENV, {
        opacity: 0,
        onComplete: () => {
          cloak.style.left = '100%'
          cloak.style.opacity = 1
        },
      })
    )
    .add(
      TweenMax.to(pac, DURATIONS.ENV, {
        scale: 1,
      }),
      DURATIONS.EYES
    )
}

const showPassword = () => {
  const pacTimeline = new TimelineMax()
  pacTimeline
    .add(
      TweenMax.to(input, DURATIONS.ENV, {
        onStart: () => {
          ghost.style.backgroundColor = COLORS.GHOST[Math.floor(Math.random() * COLORS.GHOST.length)]
        },
        letterSpacing: 15,
        backgroundColor: COLORS.BG,
        color: 'yellow',
      })
    )
    .add(
      TweenMax.to(cloak, DURATIONS.ENV, {
        backgroundColor: COLORS.BG,
      }),
      0
    )
    .add(
      TweenMax.to(pac, DURATIONS.CHOMP, {
        right: '105%',
        ease: Power0.easeNone,
        onStart: () => {
          pac.classList.add('pac-input__pac--chomping')
        },
        onComplete: () => {
          pac.classList.remove('pac-input__pac--chomping')
          input.setAttribute('type', 'text')
        },
      })
    )
    .add(
      TweenMax.to(cloak, DURATIONS.CHOMP, {
        left: -5,
        ease: Power0.easeNone,
      }),
      DURATIONS.ENV
    )
    .add(
      TweenMax.to(ghost, DURATIONS.GHOST, {
        right: 10,
        ease: Power0.easeNone,
      })
    )
    .add(
      TweenMax.to(cloak, DURATIONS.GHOST, {
        left: '100%',
        ease: Power0.easeNone,
      }),
      DURATIONS.ENV + DURATIONS.CHOMP
    )
    .add(
      TweenMax.to(input, DURATIONS.ENV, {
        letterSpacing: 1,
        backgroundColor: COLORS.INPUT,
        color: 'black',
      })
    )
    .add(
      TweenMax.to(cloak, DURATIONS.ENV, {
        backgroundColor: COLORS.INPUT,
      }),
      DURATIONS.ENV + DURATIONS.CHOMP + DURATIONS.GHOST
    )
}

pac.addEventListener('click', showPassword)
ghost.addEventListener('click', hidePassword)

            
          
!
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