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 class="container">
    <div class="core-shadow">
      <div class="shadow"></div>
    </div>
    <div class="eight-ball">
      <div class="circle">
        <div class="display">
          <div class="triangle-wrap">
            <div class="triangle t4"></div>
            <div class="triangle t3"></div>
            <div class="triangle t2"></div>
            <div class="triangle t1">
              <span class="fortune"></span>
            </div>
          </div>
        </div>
      </div>
      <div class="num-eight">8</div>
      <div class="highlight"></div>
    </div>
    <div class="border-shadow"></div>
  </div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Roboto&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Graduate&display=swap');

@mixin mainFlex {
  display: flex;
  align-items: center;
  justify-content: center;
}

@keyframes triangleFloat {
  25%      { transform: rotateY(10deg) rotateZ(-3deg); }
  50%     { transform: rotateY(0) rotateZ(0); }
  75%     { transform: rotateY(-10deg) rotateZ(3deg); }
  100%     { transform: rotateY(0) rotateZ(0); }
}

* {
  margin: 0;
  padding: 0;
  font-family: 'Roboto', sans-serif;
  font-size: 0.8rem;
  color: rgba(255,255,255,0.6);
  text-transform: uppercase;
  user-select: none;
}

body {
  @include mainFlex();
  background: #808080;
  height: 100vh;
}

.core-shadow, .shadow, .eight-ball, .circle, 
.display, .triangle, .fortune, .num-eight, .highlight, .border-shadow {
  position: absolute;
}

.core-shadow, .shadow, .eight-ball, 
.circle, .display, .num-eight, .highlight, .border-shadow {
  border-radius: 50%;
}

.container {
  @include mainFlex();
  width: 500px;
  height: 500px;
  position: relative;
  .core-shadow {
    @include mainFlex();
    width: 320px;
    height: 40px;
    bottom: 35px;
    background: rgba(0,0,0,0.4);
    filter: blur(8px);
    .shadow {
      width: 240px;
      height: 15px;
      background: rgba(0,0,0,0.9);
      filter: blur(8px);
    }  
  }
  .eight-ball {
    @include mainFlex();
    position: relative;
    overflow: hidden;
    mask-image: radial-gradient(white, black);
    -webkit-mask-image: -webkit-radial-gradient(white, black);
    width: 400px;
    height: 400px;
    background: #222;
    box-shadow:
      inset 15px 15px 30px #000,
      inset -20px -20px 40px #000,
      inset -25px 25px 25px rgba(255,255,255,0.2),
      inset 25px -25px 50px rgba(255,255,255,0.3);
    &:hover {
      cursor: pointer;
    }
    .circle {
      @include mainFlex();
      width: 220px;
      height: 220px;
      background: #111;
      box-shadow: 
        inset 0 -3px 3px rgba(255,255,255,0.3),
        -2px -1px 5px rgba(255,255,255,0.2),
        2px -2px 3px #000;
      transform: translateX(-400px) scaleX(0);
      .display {
        @include mainFlex();
        width: 200px;
        height: 200px;
        background: #020214;
        border: 5px solid #000;
        box-sizing: border-box;
        box-shadow: 
          inset 0 10px 10px #000,
          inset 0 -3px 5px rgba(255,255,255,0.15),
          -1px -2px 3px rgba(255,255,255,0.1);
        .triangle {
          @include mainFlex();
          border-top: 110px solid rgba(64,0,255,0.5);
          border-left: 68px solid transparent;
          border-right: 68px solid transparent;
          width: 0;
          height: 0;
          filter: blur(2px);
          animation: triangleFloat 8s linear infinite;
        }
        .t4 {
          bottom: 29px;
          left: 26px;
        }
        .t3 {
          bottom: 22px;
          left: 21px;
        }
        .t2 {
          bottom: 22px;
          left: 31px;
        }
        .t1 {
          bottom: 24px;
          left: 26px;
          filter: none;
          .fortune {
            width: 60px;
            top: -87px;
            text-align: center;
          }
        } 
      }
    }
    .num-eight {
      @include mainFlex();
      font-family: 'Graduate', sans-serif;
      font-size: 10rem;
      color: #222;
      width: 170px;
      height: 170px;
      background: #f5efdf;
      z-index: 2;
      opacity: 0.7;
    }
    .highlight {
      width: 120px;
      height: 70px;
      background: rgba(255,255,255,0.2);
      top: 50px;
      left: 55px;
      transform: rotate(-35deg);
      filter: blur(25px);
    }
  }
  .border-shadow {
    z-index: 3;
    width: 400px;
    height: 400px;
    box-shadow: inset 0 0 10px rgba(0,0,0,1);
    &:hover {
      cursor: pointer;
    }
  }
  @media screen and (max-width: 767px) {
    transform: scale(0.75);
  }
}
              
            
!

JS

              
                document.addEventListener('DOMContentLoaded', () => {

  const eightBall = document.querySelector('.eight-ball'),
        numEight = document.querySelector('.num-eight'),
        display = document.querySelector('.circle'),
        triangles = document.querySelector('.triangle-wrap'),
        fortune = document.querySelector('.fortune'),
        borderShadow = document.querySelector('.border-shadow'),
        coreShadow = document.querySelector('.core-shadow');

  triangles.style.opacity = '0';

  const answers = [
    'It is certain',
    'It is decidedly so',
    'Without a doubt',
    'Yes definitely',
    'You may rely on it',
    'As I see it, yes',
    'Most likely',
    'Outlook good',
    'Yes',
    'Signs point to yes',
    'Reply hazy try again',
    'Ask again later',
    'Better not tell you now',
    'Cannot predict now',
    'Concentrate and ask again',
    'Do not count on it',
    'My reply is no',
    'My sources say no',
    'Outlook not so good',
    'Very doubtful'
  ]; 

  let nPosX = 1,
      nScale = 1,
      dPosX = -400,
      dScale = 0.5;

  const rotate = () => {
    numEight.style.transform = `translateX(${nPosX}px) scaleX(${nScale})`;

    nPosX++;
    nScale -= 0.00248756219; // this num is a product of trial and error
    if (nScale === 0.5) {
      numEight.style.tranform = 'scaleX(0)';
    }

    dPosX++;
    if (dPosX < -200) {
      display.style.transform = `translateX(${dPosX}px) scaleX(0)`;
    } else {
      dScale += 0.00248756219;
      display.style.transform = `translateX(${dPosX}px) scaleX(${dScale})`;
    }
    
    if (dPosX < 0) {
      setTimeout(() => rotate(), 10);
    } else {
      borderShadow.style.display = 'none';
      fortune.textContent = 'Ask a question';
      setTimeout(() => fadeIn(), 1000);
      setTimeout(() => fadeOut(), 4000);
    }
  }

  const shake = () => {
    setTimeout(() => {
      eightBall.style.transform = 'translateY(-40px)';
      coreShadow.style.transform = 'scale(0.85)';
    }, 100);
    setTimeout(() => {
      eightBall.style.transform = 'translateX(-40px) translateY(-40px)';
      coreShadow.style.transform = 'scale(0.85) translateX(-40px)';
    }, 400);
    setTimeout(() => {
      eightBall.style.transform = 'translateX(0) translateY(-40px)';
      coreShadow.style.transform = 'scale(0.85) translateX(0)';
    }, 500);
    setTimeout(() => {
      eightBall.style.transform = 'translateX(40px) translateY(-40px)';
      coreShadow.style.transform = 'scale(0.85) translateX(40px)';
    }, 600);
    setTimeout(() => {
      eightBall.style.transform = 'translateX(0) translateY(-40px)';
      coreShadow.style.transform = 'scale(0.85) translateX(0)';
    }, 700);
    setTimeout(() => {
      eightBall.style.transform = 'translateY(0)';
      coreShadow.style.transform = 'scale(1)';
    }, 1000);
  }

  let opacity = 0;

  const fadeIn = () => {
    if (opacity < 1) {
      opacity += .1;
      setTimeout(() => fadeIn(), 100);
    }
    triangles.style.opacity = opacity;
  }

  const fadeOut = () => {
    if (opacity > 0) {
      opacity -= .1;
      setTimeout(() => fadeOut(), 100);
    }
    triangles.style.opacity = opacity;
  }

  const askMagicEightBall = () => {
    const random = Math.floor(Math.random() * answers.length);
    fortune.textContent = answers[random];
    shake();
    setTimeout(() => fadeIn(), 1000);
    setTimeout(() => fadeOut(), 4000);
  }

  borderShadow.addEventListener('click', () => rotate());

  eightBall.addEventListener('click', () => opacity > 0 ? false : askMagicEightBall() );

});
              
            
!
999px

Console