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

              
                <div class="helper"><p>Use your mouse or finger to drag the credit card</p></div>

<div id="target" class="credit-card">
  <div class="credit-card__header">
    <div class="credit-card__header__logo">
      <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAK8AAABxCAYAAACjpvMqAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4QUaFSo4uwxPIQAADxxJREFUeNrtnXlwVfUVxz/35SUkgBgIhAAaQKsigkqrFRfct462gzjiXquiLbaKxTIitKNV605FK7a1dava6tSK41qqAu6oFcQioCiLyhIISICEAMm7/eOcNwQMyXu/u773ft+ZOwkZ7va733vu+Z3z/Z3juKkUFrFGEVAKdAEqgJ5AD/29AuisWzdgN/2/CaAZaATqgfVAHbAJWKvbGmAV8A2wEWjQfcKF4xjvmrTciB1KgUpgD2BvoL9uewFVQHclqheklMxrgNXAYmARsAz4HFihf98c54FyrOWNBSqVoAcA3wMG67+rQjYwTcBKYCkwH3hPfy4FauJmeS15o0OFknUocAwwQK1tSYyucYuSeT7wFvA68BlQa8lbeEgAB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CYPmQz2GGAs3jTKcccyYALSUixIzMe8slLsyJvGUkTRdT6S1Ig6BFWLCIvOAx5E4pgmcEPezwveAa7AfAV4e2jSCWJTyOPY7r5Jn25wpg7iMUjm7EREEBOW+mgd8JYS9mUPpG35Upu82FGtInkVEUHdBJzi43FrEPHTDMP9iww5kMhkv6SPN7pVJxFvAQMQEc0JiJ5hz4Ae2kJ9aZ7T86716bilhuTtEiGBP0CiQZciS7IGenRHZipx30bS+NnCQRIfjuE4tjv+jpsKdL5VgSzOHIikMw9EpIm9MBNG12rEYw7wrv78HG+rP1rDoUhKPJvBKVY36nHMC3b75QoOAk4CjkcENtXtkKhOIwrzdFzfVT/Xa1z3FOBospNxliGRoWdxnK1Rkndna9ZViVuNCEuqkNRkpb6lSbVcrn76NyAp6hr9uVi3NUgHzqDgtLiObPZJxSj64qjx6IfoU/bQ8U/qfTXp+K5R4i5FatZt8NF3T7tf2Y+j47Q7jv8HT/KEOHwuT4AAAAAASUVORK5CYII=" alt="Citi logo" />
    </div>
    <div class="credit-card__header__type credit-card__header__type--maestro"></div>
  </div>
  <div class="credit-card__iban">
    <span>4112</span>
    <span>1645</span>
    <span>8236</span>
    <span>1134</span>
  </div>
  <div class="credit-card__valid">
    <span class="credit-card__valid__label">Valid thru</span>
    <span class="credit-card__valid__date">06/12</span>
  </div>
  <div class="credit-card__owner">
    <span>Donald Trump</span></div>
</div>
</div>
              
            
!

CSS

              
                @import 'bourbon';
@import url('https://fonts.googleapis.com/css?family=Noto+Sans');
@import url('https://fonts.googleapis.com/css?family=Share+Tech+Mono');

$background-color: #3A3A47;
$color-2: #DF3A62;
$color-3: #7E57C2;

body {
  color: white;
  overflow: hidden;
  background: $background-color;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  perspective: 10em;
}

.helper {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  text-align: center;
}

.credit-card {
  transition: transform 500ms $ease-out-expo;
  cursor: move;
  color: white;
  width: 20em;
  font-family: 'Share Tech Mono', monospace;
  border-radius: 1em;
  text-align: left;
  padding: 1em;
  background: #DF3A62;
  background: #7E57C2;
  background: linear-gradient(135deg, $color-2 0%, $color-3 100%);
  position: absolute;
  z-index: 10;
}

.credit-card__header {
  pointer-events: none;
  margin: .5em 0 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.credit-card__header__logo {
  pointer-events: none;
  display: inline-block;
  
  img {
    width: 4em;
  }
}

.credit-card__header__type {
  pointer-events: none;
  width: 3em;
  height: 2em;
  display: inline-block;
}

.credit-card__header__type--maestro {
  position: relative;
  
  &:before,
  &:after {
    border-radius: 50%;
    content: '';
    width: 2em;
    height: 2em;
    background: white;
    position: absolute;
  }
  
  &:before {
    opacity: 0.75;
    left: 0;
  }
  
  &:after {
    opacity: 0.4;
    right: 0;
  }
}

.credit-card__iban {
  pointer-events: none;
  margin: 2em 0 0;
  display: flex;
  justify-content: space-between;
  
  > span {
    display: block;
    font-size: 1.8em;
  }
}

.credit-card__valid {
  pointer-events: none;
  margin: 1em 0 0;
  display: flex;
  align-items: center;
  
  &__label {
    font-size: .8em;
    text-transform: uppercase;
    text-align: left;
    display: inline-block;
    height: 2em;
    width: 3em;
  }
  
  &__date {
    margin-left: 1em;
    font-size: 1.2em;
    display: inline-block;
  }
}

.credit-card__owner {
  pointer-events: none;
  margin: 1.5em 0 0;
  > span {
    text-transform: uppercase;
    font-size: 1.4em;
  }
}
              
            
!

JS

              
                const target = document.getElementById('target')

const mousemove = Rx.Observable.fromEvent(document, 'mousemove')
const touchmove = Rx.Observable.fromEvent(document, 'touchmove')

const mousedown = Rx.Observable.fromEvent(target, 'mousedown')
const touchstart = Rx.Observable.fromEvent(target, 'touchstart')

const mouseup = Rx.Observable.fromEvent(document, 'mouseup')
const touchend = Rx.Observable.fromEvent(document, 'touchend')

const mousedrag = mousedown.flatMap(md => {
  const rect = target.getBoundingClientRect()

  const startX = md.offsetX
  const startY = md.offsetY
  
  return mousemove.map(mm => {
    mm.preventDefault()
    
    return {
      left: mm.clientX - startX,
      top: mm.clientY - startY
    }
  }).takeUntil(mouseup)
})

const touchdrag = touchstart.flatMap(ts => {
  const rect = target.getBoundingClientRect()
  
  const startX = ts.targetTouches[0].clientX - rect.left
  const startY = ts.targetTouches[0].clientY - rect.top
  
  return touchmove.map(tm => {
    tm.preventDefault()
    
    return {
      left: tm.targetTouches[0].clientX - startX,
      top: tm.targetTouches[0].clientY - startY
    }
  }).takeUntil(touchend)
})

const drag = Rx.Observable.merge(mousedrag, touchdrag)

const dt = 5

const velocity = drag.throttle(dt).pairwise().map(md => {
  let sx = md[1].left - md[0].left
  let sy = md[0].top - md[1].top
  
  let vx = sx / dt // pixels/milisecond
  let vy = sy / dt
  
  return { vx, vy }
})

velocity.subscribe(vel => {
  let x = vel.vx * 2
  let y = vel.vy * 2
  
  let maxAngle = 7
  
  if (x > maxAngle) x = maxAngle
  if (x < -maxAngle) x = -maxAngle
  if (y > maxAngle) y = maxAngle
  if (y < -maxAngle) y = -maxAngle
  
  target.style.transform = `rotateX(${y}deg) rotateY(${x}deg)`
})

mousedown.subscribe(md => target.style.transformOrigin = `${md.offsetX}px ${md.offsetY}px`)
touchstart.subscribe(ts => target.style.transformOrigin = `${ts.offsetX}px ${ts.offsetY}px`)

drag.subscribe(pos => {
  target.style.top = `${pos.top}px`
  target.style.left = `${pos.left}px`
})

mouseup.subscribe(mo => target.style.transform = 'rotateX(0) rotateY(0)')
touchend.subscribe(te => target.style.transform = 'rotateX(0) rotateY(0)')

// initial position
const rect = target.getBoundingClientRect()
target.style.top = `${(window.innerHeight - rect.height) / 2}px`
target.style.left = `${(window.innerWidth - rect.width) / 2}px`


              
            
!
999px

Console