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

              
                .<div id="ship-interior">
  <div id="sarcophagus-viewport"
      v-on:mouseover="calculateThird, flashlightOn = true"
      v-on:mousemove="calculateThird"
      v-on:touchstart="calculateThird"
      v-on:touchmove="calculateThird"
      v-on:mouseleave="flashlightOff"
      v-on:touchend="flashlightOff"
      v-on:touchcancel="flashlightOff">
    <img id="face_bg" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_bg.jpg" srcset="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_bg2x.jpg 2x" alt=''>
    <transition name="flashlight">
      <img v-if="flashlightX === 'right' && flashlightY === 'bottom'" key="face_bot_r" class="face_shadow" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_bottom-right.png" srcset="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_bottom-right2x.png 2x" alt=''>
      <img v-else-if="flashlightX === 'center' && flashlightY === 'bottom'" key="face_bot_c" class="face_shadow" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_center-bottom.png" srcset="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_center-bottom2x.png 2x" alt=''>
      <img v-else-if="flashlightX === 'center' && flashlightY === 'middle'" key="face_mid_c" class="face_shadow" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_center-center.png" srcset="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_center-center2x.png 2x" alt=''>
      <img v-else-if="flashlightX === 'left' && flashlightY === 'middle'" key="face_mid_l" class="face_shadow" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_center-left.png" srcset="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_center-left2x.png 2x" alt=''>
      <img v-else-if="flashlightX === 'left' && flashlightY === 'bottom'" key="face_bot_l" class="face_shadow" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_left-bottom.png" srcset="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_left-bottom2x.png 2x" alt=''>
      <img v-else-if="flashlightX === 'right' && flashlightY === 'middle'" key="face_mid_r" class="face_shadow" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_right-center.png" srcset="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_right-center2x.png 2x" alt=''>
      <img v-else-if="flashlightX === 'center' && flashlightY === 'top'" key="face_top_c" class="face_shadow" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_top-center.png" srcset="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_top-center2x.png 2x" alt=''>
      <img v-else-if="flashlightX === 'left' && flashlightY === 'top'" key="face_top_l" class="face_shadow" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_top-left.png" srcset="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_top-left2x.png 2x" alt=''>
      <img v-else-if="flashlightX === 'right' && flashlightY === 'top'" key="face_top_r" class="face_shadow" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_top-right.png" srcset="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_top-right2x.png 2x" alt=''>
      <img v-else-if="flashlightX === undefined && flashlightY === undefined" key="face_dark" class="face_shadow" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_dark.png" srcset="https://s3-us-west-2.amazonaws.com/s.cdpn.io/641/vuety_face_dark2x.png 2x" alt=''>
    </transition>
    <div v-show="flashlightOn" id="flashlight_glow" v-bind:style="flashlightStyles"></div>
  </div>
</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Kalam|Nova+Mono');

#ship-interior {
  background: #000;
  width: 100%;
  max-width: calc(1366px / 2);
  height: 100vh;
  position: relative; 
  margin: 0 auto;  
}

body { background: black;}

/* The face */
#sarcophagus-viewport {
  box-shadow: 0px 20px 78px 0px rgba(0,0,0,1);
  border: #000 3px solid;
  border-radius: 50%;
  overflow: hidden;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 512px; 
}

.face_shadow {
  position: absolute;
  top: 0; left: 0;
}

.flashlight-enter-active,
.flashlight-leave-active {
  transition: opacity 400ms;
}

.flashlight-enter {
  transition-timing-function: ease-out;  
}

.flashlight-leave-to {
  transition-timing-function: ease-out;  
}

.flashlight-enter, .flashlight-leave-to {
  opacity: 0;
}

/* special radial gradient using easing curve: https://larsenwork.com/easing-gradients/ */
#flashlight_glow {
  height: 200px; width: 200px;
  transform: translate(-50%, -50%);
  background: radial-gradient(closest-side, hsl(0, 0%, 100%) 0%, hsla(0, 0%, 100%, 0.933) 5.2%, hsla(0, 0%, 100%, 0.863) 10.1%, hsla(0, 0%, 100%, 0.792) 14.9%, hsla(0, 0%, 100%, 0.721) 19.7%, hsla(0, 0%, 100%, 0.651) 24.5%, hsla(0, 0%, 100%, 0.582) 29.5%, hsla(0, 0%, 100%, 0.515) 34.6%, hsla(0, 0%, 100%, 0.449) 40%, hsla(0, 0%, 100%, 0.386) 45.6%, hsla(0, 0%, 100%, 0.325) 51.5%, hsla(0, 0%, 100%, 0.266) 57.7%, hsla(0, 0%, 100%, 0.211) 64.2%, hsla(0, 0%, 100%, 0.16) 70.9%, hsla(0, 0%, 100%, 0.113) 77.9%, hsla(0, 0%, 100%, 0.07) 85.2%, hsla(0, 0%, 100%, 0.032) 92.7%, hsla(0, 0%, 100%, 0) 100%);
  position: absolute;
  pointer-events: none;
};
              
            
!

JS

              
                "use strict";

const app = new Vue({
  el: "#ship-interior",
  data: { 
    flashlightX : undefined,
    flashlightY: undefined,
    flashlightOn: false,
    flashlightStyles : {
      top : undefined,
      left : undefined
    }
  },
  computed: {
  },
  methods : {
    calculateThird : function(event) {
      // mX/Y is the mouse's distance from the window's edges. 
      const mX = event.target.getBoundingClientRect().left + window.scrollX;
      const mY = event.target.getBoundingClientRect().top + window.scrollY;

      // coffinX/Y is the cursor's distance from the edges of the element we're listening on
      const coffinX = event.clientX - mX;
      const coffinY = event.clientY - mY;

      // elW/H are said element's width and height
      const elW = event.target.width;
      const elH = event.target.height;

      // if the cursor's distance from the edge of the element 
      // is less than 33% of the element's width
      if (coffinX < elW * .33 ) {
        // set data's flashlightX to left and so on
        this.flashlightX = "left";
      } else if (coffinX < elW *.66) {
        this.flashlightX = "center";
      } else {
        this.flashlightX = "right";
      }

      // if the cursor's distance from the edge of the element 
      // is less than 33% of the element's height
      if (coffinY < elH * .33 ) {
        // set data's flashlightY to top and so on
        this.flashlightY = "top";
      } else if (coffinY < elH *.66) {
        this.flashlightY = "middle";
      } else {
        this.flashlightY = "bottom";
      }
      
      this.flashlightStyles.top = coffinY + "px";
      this.flashlightStyles.left = coffinX + "px";
      // console.log( "Coffin: " + coffinX + " " + coffinY)
      // console.log( "Mouse position: " + mX + " " + mY)
      // console.log("Element's width: " + elW + " " + elH)
      // console.log (" ")

    },
    flashlightOff : function(event) {
      console.log("off")
      // reset all the coordinates for next time
      this.flashlightX = undefined;
      this.flashlightY = undefined;
      // this.flashlightStyles.top = undefined;
      // this.flashlightStyles.left = undefined;

      // and turn off flashlight
      this.flashlightOn = false;
    }
  }  
});

              
            
!
999px

Console