Pen Settings

HTML

CSS

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

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

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.

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

              
                .exam
  .bear
  .xray__frame
  .xray
.instruction use mouse/finger to move x-ray
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Lato')

*
  box-sizing border-box

:root
  --pos 0

body
  background-color hsl(200, 50%, 80%)
  display flex
  align-items center
  justify-content center
  overflow auto
  padding 2rem
  position fixed
  min-height 100vh
  width 100vw
  font-family 'Lato', sans-serif

  @media(min-width 768px)
    position static


$height = 550px
$width = 300px
$mobile = 0.75
$boardHeight = $height * 0.20
$boardWidth = $width * 0.85

.bear
  height $height * $mobile
  width $width * $mobile
  background-position center

  @media(min-width 768px)
    height $height
    width $width

.bear
.xray
  background-size ($width * $mobile) ($height * $mobile)

  @media(min-width 768px)
    background-size $width $height

.exam
  cursor move
  cursor -webkit-grab
  position relative
  display flex
  justify-content center

.instruction
  position absolute
  top 50%
  left 50%
  transform translate(-50%, -50%) rotate(-90deg) translate(0, (($width * $mobile) * -0.6))
  font-weight bold
  font-size 1.5rem
  text-align center
  width 100vh
  color hsl(200, 50%, 30%)

  @media(min-width 768px)
    transform translate(-50%, -50%) rotate(-90deg) translate(0, (($width) * -0.6))

.xray
  background-color #111
  background-image url(https://jh3y-xray-bear.netlify.com/skeleton.svg)
  height ($boardHeight * $mobile)
  width ($boardWidth * $mobile)
  position absolute
  top calc(var(--pos) * 1px)
  left 50%
  background-position center calc(var(--pos) * -1px)
  transform translate(-50%, 0)

  @media(min-width 768px)
    height $boardHeight
    width $boardWidth

  &__frame
    border-radius 6px
    height (($boardHeight * $mobile) + 10px)
    width (($boardWidth * $mobile) + 10px)
    position absolute
    top calc((var(--pos) * 1px) - 5px)
    left 50%
    transform translate(-50%, 0)
    border 5px solid silver

    @media(min-width 768px)
      height ($boardHeight + 10px)
      width ($boardWidth + 10px)

    &:after
    &:before
      border-radius 10px 0 0 10px
      content ''
      position absolute
      transform translate(-100%, 0)
      height 20%
      width 10px
      left -5px

    &:before
      background #2eec7a
      top 20%

    &:after
      background #ffcb05
      top 50%


.bear
  background-image url(https://jh3y-xray-bear.netlify.com/bear.svg)
              
            
!

JS

              
                const exam = document.querySelector('.exam')
const xray = document.querySelector('.xray')
const updateXray = (e) => {
  const y = e.touches ? e.touches[0].clientY : e.y
  const examArea = exam.getBoundingClientRect()
  const xrayArea = xray.getBoundingClientRect()
  const perc = (y - examArea.top) / examArea.height
  const pos = Math.floor(Math.max(0, Math.min(perc * examArea.height, examArea.height - xrayArea.height)))
  document.documentElement.style.setProperty('--pos', pos)
}

exam.addEventListener('mousemove', updateXray)
exam.addEventListener('touchmove', updateXray)
              
            
!
999px

Console