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.

            
              mixin wheel(mod)
  .wheel(class=`wheel--${mod}`)
    .wheel__tyre.bike__tyres
    .wheel__spin
      .wheel__rim.bike__wheel
      .wheel__hub.bike__wheel
      .wheel__spokes.bike__wheel
        - for(let s = 0; s < 5; s++)
          .wheel__spoke.bike__wheel

mixin frame
  .frame.bike__frame
    .frame__toptube.frame__tube.bike__frame
    .frame__chainstay.frame__tube.bike__frame
    .frame__seattube.frame__tube.bike__frame
    .frame__bottombracket.frame__tube.bike__frame
    .frame__seatstay.frame__tube.bike__frame
    .frame__dropout.frame__tube.bike__frame
    .frame__downtube.frame__tube.bike__frame

mixin forks
  .forks.bike__forks
    .forks__steerer.bike__forks
    .forks__leg.bike__forks
    .forks__dropout.bike__forks

input.colorizer(type='color')
.instruction Click parts of bike to define custom colors 👍 (Chrome, Firefox)
.bike
  .bike__cranks
    .bike__crank
  +wheel('back')
  +wheel('front')
  +forks
  +frame
  .bike__seat
  .bike__cranks.bike__cranks--foreground
    .bike__crank
  .bike__stem
  .bike__handlebars
  .bike__basket
  .colorways
    button.colorways__choice.colorways__choice--default(data-colorway='DEFAULT', title='Set Default colorway')
    button.colorways__choice.colorways__choice--lemonandlime(data-colorway='LEMONANDLIME', title='Set Lemon & Lime colorway')
    button.colorways__choice.colorways__choice--stealth(data-colorway='STEALTH', title='Set Stealth colorway')
    button.colorways__choice.colorways__choice--skyline(data-colorway='SKYLINE', title='Set Skyline colorway')
    button.colorways__choice.colorways__choice--badbarbie(data-colorway='BADBARBIE', title='Set Bad Barbie colorway')
            
          
!
            
              

$size = 160px
$tubeWidth = 10px

$wheelSize = $size
$tyreWidth = $wheelSize / 8
$rimWidth  = $wheelSize / 10
$hubSize = 25%

$scale = 1


:root
  --frame red
  --seat black
  --handlebars red
  --forks red
  --stem black
  --mags grey
  --sprocket silver
  --pedals silver
  --tyres black
  --cranks black


.wheel
  height $wheelSize
  width $wheelSize
  position relative
  overflow hidden

  &__tyre
    border $tyreWidth solid var(--tyres)
    border-radius 100%
    height 100%
    width 100%
    overflow hidden
    position absolute
    top 0
    left 0

  &__spin
    height 80%
    width 80%
    border-radius 100%
    overflow hidden
    position relative
    position absolute
    top 50%
    left 50%
    margin-left -40%
    margin-top -40%
    animation spin .5s infinite linear

  &__rim
    border $rimWidth solid var(--mags)
    border-radius 100%
    height ($size - $tyreWidth)
    width ($size - $tyreWidth)
    overflow hidden
    position absolute
    top 50%
    left 50%
    z-index 1
    transform translate(-50%, -50%)

  &__hub
    height $hubSize
    width $hubSize
    background var(--mags)
    border-radius 100%
    position absolute
    left 50%
    top 50%
    transform translate(-50%, -50%)

  &__spokes
    height 97%
    width 100%
    position absolute
    top 0
    left 0
    overflow hidden

  &__spoke
    position absolute
    top 50%
    left 50%
    height 50%
    width 10%
    background var(--mags)
    transform-origin top center
    for $spoke in (1..5)
      &:nth-of-type({$spoke})
        transform translate(-50%, 0%) rotate(($spoke * 72deg))



// Animations
@keyframes spin
  to
    transform rotate(360deg)

$frameSize = $size
$bbSize = $frameSize * 0.25
$chainStayLength = $frameSize * 0.65
$seattubeLength = $frameSize * 0.5

.frame
  position absolute
  top 50%
  left 50%
  transform translate(-50%,-50%)
  height $bbSize
  width $bbSize

  &__tube
    background var(--frame)
    position absolute
    height $tubeWidth

  &__toptube
    width $frameSize
    transform rotate(-14deg) translate(-5%, -825%)
    left 50%

    &:after
      content ''
      display block
      position absolute
      background var(--frame)
      width ($tubeWidth * 1.2)
      height ($tubeWidth * 4)
      top -($tubeWidth * 0.5)
      right -($tubeWidth * 0.1)

  &__chainstay
    width $chainStayLength
    top 50%
    transform translate(-90%, -50%)

  &__bottombracket
    height ($bbSize * 0.75)
    width ($bbSize * 0.75)
    border-radius 100%
    top 50%
    left 50%
    transform translate(-50%, -50%)

  &__seatstay
    transform-origin left center
    top 50%
    transform translate(-($chainStayLength), -50%) rotate(-38deg)
    width $chainStayLength * 1.2

  &__dropout
    top 50%
    transform translate(-($chainStayLength) + 5%, -50%)
    height ($tubeWidth * 2)
    width ($tubeWidth * 2)
    border-radius 100%

  &__downtube
    width $frameSize
    left 50%
    top 50%
    transform-origin left center
    transform translate(0, -50%) rotate(-36deg)

  &__seattube
    width $seattubeLength
    transform-origin left center
    left 50%
    transform rotate(-109deg) translate(0%, -50%)


.forks
  position absolute
  height ($tubeWidth * 2)
  width ($tubeWidth * 2)

  &__steerer
    height ($tubeWidth * 5)
    width $tubeWidth
    background var(--forks)
    position absolute
    bottom ($tubeWidth * 9)

  &__leg
    background var(--forks)
    width $tubeWidth
    height ($tubeWidth * 9)
    transform-origin top center
    transform rotate(1deg) translateY(-1%)
    position absolute
    bottom 0

  &__dropout
    position absolute
    bottom 0
    left 0
    height ($tubeWidth * 2)
    width ($tubeWidth * 2)
    background var(--forks)
    border-radius 100%


$sprocketSize = $size * 0.25
.bike
  position absolute
  top 50%
  left 50%
  height 200px
  width 200px
  transform translate(-60%, -50%) scale(0.65)

  @media(min-width 768px)
    transform translate(-60%, -50%) scale(1)

  &__cranks
    position absolute
    top 50%
    left 50%
    margin-left -($sprocketSize / 2)
    margin-top -($sprocketSize / 2)
    background var(--sprocket)
    height $sprocketSize
    width $sprocketSize
    border-radius 100%
    animation spin 1s infinite linear

    &--foreground .bike__crank
      transform-origin top center
      transform translate(-50%, 5%) rotate(-180deg)

  &__crank
    height ($sprocketSize * 1.25)
    width ($sprocketSize * 0.25)
    background var(--cranks)
    position absolute
    top 50%
    left 50%
    transform translate(-50%, -5%)
    border-radius 30% 30% 50% 50%

    &:after
      border-radius 100%
      content ''
      height ($sprocketSize * 0.2)
      width ($sprocketSize * 0.2)
      background var(--frame)
      top 100%
      left 50%
      position absolute
      transform translate(-50%, -110%)

    &:before
      content ''
      height 20%
      width 300%
      background #404040
      position absolute
      top 100%
      left 50%
      margin-left -150%
      margin-top -100%
      animation spin 1s infinite reverse linear


  &__seat
    background var(--seat)
    position absolute
    height $size * 0.1
    width $size * 0.45
    border-radius 90%
    top 50%
    left 50%
    transform translate(-95%, -650%) rotate(-20deg)

    &:after
      content ''
      background var(--seat)
      height 120%
      width 55%
      position absolute
      border-radius 100%

  // &__basket
  //   height ($size * 0.4)
  //   width ($size * 0.6)
  //   position absolute
  //   top 50%
  //   left 50%
  //   background white
  //   transform-origin left bottom
  //   transform translate(145%, -300%) rotate(-6deg)

  &__stem
    background var(--stem)
    position absolute
    top 50%
    left 50%
    height ($tubeWidth * 1.5)
    width ($tubeWidth * 3)
    transform translate(380%, -900%) rotate(-12deg)

  &__handlebars
    background var(--handlebars)
    width $tubeWidth
    height ($tubeWidth * 9)
    border-radius 0 $tubeWidth $tubeWidth
    position absolute
    top 50%
    left 50%
    transform translate(1250%, -240%) rotate(-8deg)
    &:after
      content ''
      height $tubeWidth * 1.25
      width $tubeWidth * 2
      background black
      position absolute
      border-radius $tubeWidth
      transform-origin right center
      transform translateX(-55%) rotate(10deg)


.wheel
  position absolute
  top 50%
  left 50%

  &--back
    transform translate(-125%, -50%)

  &--front
    transform translate(50%, -50%)

.forks
  position absolute
  top 50%
  left 50%
  transform translate(750%, -50%) rotate(-15deg)


.colorways
  position absolute
  top 100%
  left 50%
  transform translate(-39%, 0)
  width 300px


  &__choice
    cursor pointer
    height 44px
    width 44px
    border 0
    border-radius 100%
    margin 4px
    box-shadow 1px 1px 1px black
    transition box-shadow .05s ease

    &:hover
      box-shadow 2px 2px 2px black

    &:active
      box-shadow 0px 0px 2px black

    &--default
      background linear-gradient(45deg, #000000 33%, #ff0000 33%, #ff0000 66%, #808080 66%)
    &--skyline
      background linear-gradient(45deg, #000000 33%, #3af4f8 33%, #3af4f8 66%, #ffffff 66%)
    &--badbarbie
      background linear-gradient(45deg, #000000 33%, #ff00ec 33%, #ff00ec 66%, #000000 66%)
    &--lemonandlime
      background linear-gradient(45deg, #ffffff 33%, #00f900 33%, #00f900 66%, #fffb00 66%)
    &--stealth
      background linear-gradient(45deg, #6e6e6e 33%, #000000 33%, #000000 66%, #c0c0c0 66%)

.bike__handlebars
.bike__seat
.bike__frame
.bike__stem
.bike__forks
.bike__wheel
.bike__cranks
.bike__tyres
.bike__crank
  cursor pointer

*, *:after, *:before
  box-sizing border-box
  transition background .25s ease 0s

body
  background radial-gradient(dodgerblue, #111)
  display flex
  align-items center
  justify-content center
  height 100vh
  width 100vw

input
  visibility hidden

.instruction
  position absolute
  bottom 6px
  color white
  font-family 'Arial', sans-serif
  font-size 14px
  @media(max-width 768px)
    display none
            
          
!
            
              const root = document.documentElement
const $bike = document.querySelector('.bike')
const $colorizer = document.querySelector('.colorizer')
const $colorways = document.querySelector('.colorways')

const CLASSMAP = {
  'bike__handlebars': '--handlebars',
  'bike__seat': '--seat',
  'bike__frame': '--frame',
  'bike__stem': '--stem',
  'bike__forks': '--forks',
  'bike__wheel': '--mags',
  'bike__cranks': '--sprocket',
  'bike__tyres': '--tyres',
  'bike__crank': '--cranks',

}

const THEMES = {
  DEFAULT: {
    '--frame': '#ff0000',
    '--seat': '#000000',
    '--handlebars': '#ff0000',
    '--forks': '#ff0000',
    '--stem': '#000000',
    '--mags': '#ffffff',
    '--sprocket': '#c0c0c0',
    '--pedals': '#c0c0c0',
    '--tyres': '#000000',
    '--cranks': '#000000',
  },
  STEALTH: {
    '--frame': '#000000',
    '--seat': '#000000',
    '--handlebars': '#6e6e6e',
    '--forks': '#6e6e6e',
    '--stem': '#000000',
    '--mags': '#ffffff',
    '--sprocket': '#6e6e6e',
    '--pedals': '#c0c0c0',
    '--tyres': '#000000',
    '--cranks': '#000000',
  },
  LEMONANDLIME: {
    '--frame': '#00f900',
    '--seat': '#000000',
    '--handlebars': '#fffb00',
    '--forks': '#fffb00',
    '--stem': '#000000',
    '--mags': '#c5c5c5',
    '--sprocket': '#ffffff',
    '--pedals': '#c0c0c0',
    '--tyres': '#000000',
    '--cranks': '#000000',
  },
  SKYLINE: {
    '--frame': '#3af4f8',
    '--seat': '#000000',
    '--handlebars': '#3af4f8',
    '--forks': '#3af4f8',
    '--stem': '#000000',
    '--mags': '#000000',
    '--sprocket': '#c0c0c0',
    '--pedals': '#c0c0c0',
    '--tyres': '#ffffff',
    '--cranks': '#000000',
  },
  BADBARBIE: {
    '--frame': '#000000',
    '--seat': '#ff00ec',
    '--handlebars': '#ff00ec',
    '--forks': '#000000',
    '--stem': '#000000',
    '--mags': '#ff00ec',
    '--sprocket': '#ff00ec',
    '--pedals': '#c0c0c0',
    '--tyres': '#000000',
    '--cranks': '#000000',
  }
}

const addOffClick = (e, cb) => {
  const offClick = (evt) => {
    if (e !== evt) {
      cb()
      document.removeEventListener('click', offClick)
    }
  }
  document.addEventListener('click', offClick)
}

const bootstrapTheme = theme => {
  for (const prop of Object.keys(theme)) {
    root.style.setProperty(prop, theme[prop])
  }
}

const handleColorChange = (e) => {
  let propToUpdate
  for (const className of e.target.classList) {
    if (CLASSMAP[className]) propToUpdate = CLASSMAP[className]
  }
  if (propToUpdate) {
    const currentValue = root.style.getPropertyValue(propToUpdate) || getComputedStyle(e.target).backgroundColor
    $colorizer.value = currentValue
    const updateColor = (e) => {
      root.style.setProperty(propToUpdate, e.target.value)
      addOffClick(e, () => {
        $colorizer.removeEventListener('input', updateColor)
      })
    }
    $colorizer.addEventListener('input', updateColor)
    $colorizer.click()
  }
}

const setColorway = (e) => {
  if (e.target.hasAttribute('data-colorway')) {
    bootstrapTheme(THEMES[e.target.getAttribute('data-colorway')])
  }
}

bootstrapTheme(THEMES.DEFAULT)
$bike.addEventListener('click', handleColorChange)
$colorways.addEventListener('click', setColorway)
            
          
!
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