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.

            
              .creature-cage
  .creature-body
    .eyeball
      .brow
      #leftPupil
    .eyeball.right
      .brow.right
      #rightPupil
    .hair-tuft
      .hair
      .hair.hair-middle-dark
      .hair.hair-right
    .hair-tuft.hair-tuft-right
      .hair
      .hair.hair-middle-dark
      .hair.hair-right
    .mouth
      .tongue
      .drool
  .hand.hand-left
    .finger
    .finger.finger-middle
    .finger.finger-right
  .hand.hand-right
    .finger
    .finger.finger-middle
    .finger.finger-right
            
          
!
            
              body
  background-color: dimgray

.eyeball,
.hair-tuft,
#leftPupil,
#rightPupil,
.drool,
.hand
  position: absolute

.creature-cage
  position: relative
  margin: auto
  border: .5rem solid #090909
  background-color: #eee
  @media (min-width: 768px)
    width: 24rem
    margin-top: 5rem
    
.creature-body
  height: 15rem
  margin: 10rem auto 0
  border-radius: 60% 60% 0 0
  background-color: #5e35b1

.eyeball
  width: 50px
  height: 50px 
  top: 30%
  left: 20%
  border-radius: 50%
  padding: 22px
  box-shadow: 2px 8px 6px darken(#280680, 5%)
  background-color: #1de9b6
  &::before
    content: ''
    position: absolute
    width: 20px
    height: 15px
    border-radius: 50%
    background-color: #FFF
    z-index: 1
  &.right
    left: 55%
    
.brow
  position: relative
  width: 80px
  height: 30px
  bottom: 45px
  right: 35px
  z-index: 20
  border: 6px solid
  border-radius: 50%
  border-color: transparent
  box-shadow: 3px -5px 1px #090909
  transform: rotate(-20deg)
  &.right
    transform: rotateY(190deg)

#leftPupil,
#rightPupil
  width: 30px
  height: 30px
  top: 2.3rem
  right: 1rem
  transform-origin: 1px
  border-radius: 50%
  padding: 2px
  background-color: #090909
  &::after
    content: ''
    position: absolute
    width: 32px
    height: 32px
    bottom: -4px
    left: -3px
    border: 5px solid #b2ff59
    border-radius: 50%
.hair-tuft
  width: 65px
  height: 50px
  left: 10%
  bottom: 25%
  &.hair-tuft-right
    left: 75%
    bottom: 13%
    transform: rotateY(180deg)
.hair
  position: relative
  width: 35px
  height: 50px
  clip-path: polygon(50% 0%, 0 100%, 100% 100%)
  background-color: #7441d9
  transform: rotateX(180deg)
  &.hair-right,
  &.hair-right-dark
    left: 40%
    bottom: 200%
  &.hair-middle-dark,
  &.hair-middle-light
    left: 20%
    bottom: 100%
  &.hair-middle-dark
    background-color: #4f2c94

.mouth
  position: relative
  width: 19%
  height: 21%
  left: 39%
  top: 45%
  border-radius: 13% 13% 50% 50%
  background-color: #090909

.tongue
  position: relative
  width: 72%
  height: 26%
  left: 7%
  bottom: -46%
  border: 6.5px dashed
  border-color: transparent transparent white
  border-radius: 50%
  background-color: #ec407a

.drool
  top: 61%
  width: 10px
  border-radius: 27% 50% 20% 77%
  box-shadow: 4px 8px 7px darken(#280680, 5%)
  background: linear-gradient(#00bcd4, #80deea)
  animation: drooling 2.5s 2s cubic-bezier(.73,-0.44,.43,1.49)
  animation-fill-mode: forwards

.hand
  width: 90px
  height: 55px
  top: 96%
  &.hand-left
    left: 10%
    transform: rotateY(180deg)
  &.hand-right
    right: 10%
  .finger
    position: relative
    width: 25%
    height: 85%
    border-radius: 20% 20% 50% 50%
    box-shadow: 0px 3px 15px #090909
    background-color: #9162e4
    &.finger-middle
      width: 25%
      height: 94%
      left: 29%
      bottom: 80%
    &.finger-right
      width: 20%
      height: 68%
      left: 60%
      bottom: 164%

@keyframes drooling
  0%
    height: 0px
    opacity: 0
  70%
    height: 20px
  100%
    height: 42px
    opscity: .5
            
          
!
            
              const rightPupil = document.getElementById('rightPupil'),
  rightPupilPositionInfo = rightPupil.getBoundingClientRect(),
  leftPupil = document.getElementById('leftPupil'),
  leftPupilPositionInfo = leftPupil.getBoundingClientRect()

const Eye = class Eye {
  constructor(pupilDirection, pupilPositionX, pupilPositionY) {
    this.pupilDirection = pupilDirection
    this.pupilPositionX = pupilPositionX
    this.pupilPositionY = pupilPositionY
  }
  
  findAngle(cursorY, cursorX) {
    let angleDeg = Math.atan2(cursorY - this.pupilPositionY, cursorX - this.pupilPositionX) * 180 / Math.PI 
    //angle in degrees
    angleDeg = (angleDeg >= 360) ? angleDeg -= 360 : (angleDeg < 0) ? angleDeg += 360 : angleDeg -= 360
    this.rotatePupil(angleDeg)
  }
 
  rotatePupil(angleDeg) {
    this.pupilDirection.style.transform = `rotate(${angleDeg}deg)`
  }
}

const rightEye = new Eye(rightPupil, rightPupilPositionInfo.x, rightPupilPositionInfo.y)
const leftEye = new Eye(leftPupil, leftPupilPositionInfo.x, leftPupilPositionInfo.y)

 const getCursorCoordinates = (e) => {
    let cursorY = (e.clientY),
        cursorX = (e.clientX)
   rightEye.findAngle(cursorY, cursorX)
   leftEye.findAngle(cursorY, cursorX)
}
 
document.addEventListener('mousemove', getCursorCoordinates, false)

// var eyeFollow = (e) => {
//   let y1 = (e.clientY),
//     y2 = pupilPositionInfo.y,
//     x1 = (e.clientX), 
//     x2 = pupilPositionInfo.x, 
//     angleDeg = Math.atan2(y1 - y2, x1 - x2) * 180 / Math.PI; //angle in degrees
  

//   if(angleDeg >= 360){ 
//     angleDeg -= 360;
//   }else if(angleDeg < 0){
//     angleDeg += 360;
//   }
  
//   pupil.style.transform = `rotate(${angleDeg}deg)`
// }


// function eyePoke(e) {
//   //gets position of our eye relative to the body
//   let x = pupilPositionInfo.x - document.body.offsetLeft,
//     y = pupilPositionInfo.y - document.body.offsetTop,
//     eyeballWidth = parseInt(window.getComputedStyle(eyeball).getPropertyValue("width")),
//     y1 = parseInt((e.clientY) - y),
//     x1 = parseInt((e.clientX) - x)
 
//   // checks position cursor to keep it confined to eye area
//  if(x1 > 0) x1 -= x1; //15
//   if(x1 < (eyeballWidth * -.5)) x1 = -40; //-40
//   if(y1 > (eyeballWidth * .25)) y1= 20; //15
//   if(y1 < (eyeballWidth * -.5)) y1 = -30; //30
//   pupil.style.transform = `translate(${x1}px,${y1}px)`
  
// }



            
          
!
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