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="machine_body">
  <div class="inside_glass">
    <div class="drinks">
      <div class="drink">
        <img src="https://assets.codepen.io/2970881/red1.png" />
      </div>
      <div class="drink">
        <img src="https://assets.codepen.io/2970881/pink2.png" />
      </div>
      <div class="drink">
        <img src="https://assets.codepen.io/2970881/lime.png" />
      </div>
      <div class="drink">
        <img src="https://assets.codepen.io/2970881/orange.png" />
      </div>
    </div>
  </div>
  <div class="glass"></div>
  <div class="btn_container">
      <div class="buttons">
    <div class="btn_row">
      <div class="btn" id="red">
        <h1>sold out</h1>
      </div>
      <div class="select red"></div>
    </div>

    <div class="btn_row">
      <div class="btn" >
        <h1>$2.00</h1>
      </div>
      <div class="select stock" id="pink"></div>
    </div>
    <div class="btn_row">
      <div class="btn" >
        <h1>$2.00</h1>
      </div>
      <div class="select stock" id="lime"></div>
    </div>
    <div class="btn_row">
      <div class="btn" >
        <h1>$2.00</h1>
      </div>
      <div class="select stock" id="teal"></div>
    </div>
  </div>
  </div>

  <div class="bottom">
    <div class="slot">
    </div>
    <div id="slot" class="img">
<img id="soda" src="https://assets.codepen.io/2970881/pink_r.png" />
    </div>
    <div class="insert">
      <h1>CASH</h1> 
    </div>

  </div>

</div>
              
            
!

CSS

              
                $t: transparent;
$teal: #54D9D1;
$dteal: #43ada7;
$pink: #F27A9B;
$orange: #EB7131;
$do: #d96d8b;
$bk: #fff;
$ddteal: #29b88c;
@mixin for-phone-only {
  @media (max-width: 599px) {
    @content;
  }
}
@mixin for-tablet-portrait-up {
  @media (min-width: 600px) {
    @content;
  }
}
@mixin for-tablet-landscape-up {
  @media (min-width: 900px) {
    @content;
  }
}
@mixin for-desktop-up {
  @media (min-width: 1200px) {
    @content;
  }
}
@mixin for-big-desktop-up {
  @media (min-width: 1800px) {
    @content;
  }
}
*{
  margin: 0;
  box-sizing: border-box;
}
body{
  overflow: hidden;
  font-size: 1.3vmin;
  
background-color: silver;
background-image: linear-gradient(335deg, #F6E2C3 23px, transparent 23px),
linear-gradient(155deg, #F6E2C3 23px, transparent 23px),
linear-gradient(335deg, #F6E2C3 23px, transparent 23px),
linear-gradient(155deg, #F6E2C3 23px, transparent 23px);
background-size: 58px 58px;
background-position: 0px 2px, 4px 35px, 29px 31px, 34px 6px;  

  @include for-phone-only {

  }    
}
.machine_body {
  @include for-phone-only {
  height: 87em;
    top: 63.5%;
  }   
  width: 70em;
  height: 62em;
  position: absolute;
  top: 60%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 7px;
background: 
  $dteal,
  ; 
  background-repeat: no-repeat;
  
  .inside_glass{
    border-radius: 14px;
    width: 61.5em;
    height: 21.5em;
    position: absolute;
    left: 50%;
    top: 5%;
    transform: translate(-50%,0); 
    background: 
// top bar      
    linear-gradient(
      rgba(#dcdcdc,.5)40%, 
      // rgba(#dcdcdc,.0),
      rgba($teal,.5)55%,
      rgba($t,.3),
    ) 
 51% 0% / 57.1em 20em,         
// btm bar      
    linear-gradient(
      to right, 
      rgba(#dcdcdc,.7) 50%, 
      rgba(#dcdcdc,.7) 51%,
    ) 
 50.8% 100% / 47.2em 1.7em,      
// left corner      
    linear-gradient(
      to right, 
      rgba(#dcdcdc,.7) 20%, rgba($do,0) 65%,
    ) 
 97.5% 0% / .6em 20em,        
    linear-gradient(
      45deg, 
      rgba(#dcdcdc,.8) 42%, 
      rgba(#dcdcdc,.7) 43%,
      rgba(#dcdcdc,.7) 44.5%,
      rgba($t,.0) 45%,
    ) 
 54.4em 106% / 15em 2.8em,   
// left corner      
    linear-gradient(
      to right, 
      rgba(#dcdcdc,.7) 20%, rgba($do,0) 65%,
    ) 
 3.6% 0% / .6em 20em,        
    linear-gradient(
      -45deg, 
      rgba(#dcdcdc,.8) 42%, 
      rgba(#dcdcdc,.7) 43%,
      rgba(#dcdcdc,.7) 44.5%,
      rgba($do,0) 45%,
    ) 
 -7.75em 106% / 15em 2.8em,       
      rgba(#fff,.3); 
      ;
    background-repeat: no-repeat;
    .drinks{
    position: absolute;
    width: 50em;
    height: 16.5em;
    top: 10%;
    left: 50%;    
    transform: translate(-50%,0);
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
.drink {

  font-family: 'Pacifico', cursive;
  width: 20%;
  height: 100%;
  background-repeat: no-repeat;
  text-align:center;
  position: relative;
  top: 0%;
  img{
  @include for-phone-only {
    width:50px;
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -25%);
  }      
    width: 9.5em;
  }
}      
    }
  }
  .glass{
    width: 61.5em;
    height: 21.5em;
    border-radius: 15px;
    position: absolute;
    left: 50%;
    top: 5%;
    transform: translate(-50%,0);
    border-top: 2px solid rgba(#2e7672,1);
    border-left: 2px solid rgba(#2e7672,1);
    border-right: 2px solid rgba(#2e7672,1);
    background:           
      rgba(#fff,.2) 
      ;
    background-repeat: no-repeat;
    &:after{
      border-radius: 15px; 
    width: 61.5em;
    height: 21.5em;
      content: ''; 
      position: absolute;
      left: -.6%;
      top: -2.5%;
      border-top: 2px solid $teal;
      border-left: 2px solid $teal;
      border-right: 2px solid $teal;
    }
  }
  .btn_container{
    z-index: 6;
    width: 100%;
    height: 10em;
    background: $dteal;
    position: absolute;
    top: 40.5%;
  @include for-phone-only {
      top: 32%;
  }        
  }
  .buttons{
    background: $dteal;
    position: absolute;
    width: 50em;
    height: 8.5em;
    top: 48%;
    left: 50%;
    transform: translate(-50%,-50%);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 7px;
    text-align: center;
    
    .btn_row{
      display: flex;
      flex-direction: column;
      // background: yellow;
      height: 100%;
    }
    .btn{
      border-radius: 5px;
      width: 7.5em;
      height: 4em;
      border: 2px solid #4BC3BC;
      position: relative;
      background: 
        linear-gradient(
          to bottom,
          rgba($pink,.4),
          rgba(#fff,.1)),
        
        $teal;
      &:after{
        width: 7.5em;
        height: 3.8em; 
        border-top: 1px solid #215653;
        border-right: 2px solid #215653;
        content: '';
        
        position: absolute;
        border-radius: 5px;
        top: 0%;
        left: 50%;
        transform:translate(-50%,0%); 
      }
      h1{
      text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 2px 
#87E4DE, 0 0 2px 
#87E4DE, 0 0 2px 
#87E4DE, 0 0 3px 
#87E4DE, 0 0 5px  
#87E4DE;             
        font-family: 'Pacifico', cursive;
        font-size: 1.5em;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        color: #232323;
      }
    }
      .red.select{
      width: 2.5em;
      height: 2.5em;        
      &:after{
        content: '';
        width: 2em;
        height: 2em;
        border-radius: 50%;
        position: absolute;
        top: 50%;
        left: 50%;
        transform:translate(-50%,-50%);
        background: #8B0C00;
        box-shadow: 1px 1px 1px 1px rgba(#232323,.6);
      }        
      }      
 
    .select{
      margin-top: 15px;
      width: 2.5em;
      height: 2.5em;
      background: #C0C0C0;
      border-radius: 50%;
      margin: auto;
      align-self: flex-end;
      border: 2px solid #C0C0C0;
      position: relative;
      &:after{
        content: '';
        width: 2em;
        height: 2em;
        border-radius: 50%;
        position: absolute;
        top: 50%;
        left: 50%;
        transform:translate(-50%,-50%);
        background: #e6e6e6;;
        box-shadow: 1px 1px 1px 1px rgba(#232323,.6);
      }
    }
  }
  
  .bottom{
  @include for-phone-only {
    top: 65em;
    height: 45em;
  }        
    background: $dteal;
    position: absolute;
    width: 61.5em;
    height: 25em;
    top: 47em;
    left: 50%;
    transform: translate(-50%,-50%);
  }
  .slot{
  @include for-phone-only {
    top: 67%;

  }        
    z-index: 3;
    font-family: 'Pacifico', cursive;
    width: 27em;
    height: 13em;
    border: 2px solid $dteal;
    border-bottom: 2px solid #87e4de;
    position: absolute; 
    border-radius: 7px;
    left: 25%;
    top: 50%;
    transform: translate(-50%,-50%); 
    border-top:2px solid #2e7672;
    border-left: 1px solid #2e7672;
    border-right:2px solid #2e7672;
    box-shadow: inset 10px 10px 15px 8px rgba(#232323,.5);
    background-repeat: no-repeat;
    img{
      width: 9.5em;
      transform: rotate(-90deg) translate(80%,-25%);
      left: 50%;
      position: absolute;
      top: 50%;
    }
    h1{
      font-size: 4.5em;
      font-weight: bolder;
      color: #E0E0E0;
      left: 48%;
      top: 48%;
      transform: translate(-50%,-50%); 
      position: absolute;
      text-shadow: 0 0 3px #C0C0C0, 0 0 3px #C0C0C0, 0 0 2px 
#C0C0C0, 0 0 2px 
#C0C0C0, 0 0 2px 
#C0C0C0, 0 0 3px 
#C0C0C0, 0 0 5px  
#C0C0C0;              
    }
    &:after{
      content: '';
      width: 27em;
      height: 7em; 
      position: absolute;
      background: $dteal;
      top: -57.4%;
      @include for-phone-only {
        top: -120%;
        height: 14em; 
      }           
    }
  }
  .img{
    position: absolute;
    z-index: 2;
    width: 27em;
    height: 8em;
    left: 4%;
    img{
  @include for-phone-only {
      top: 390%;
  }        
      width: 18.5em;
      transform: translate(-50%,-50%);
      left: 50%;
      position: absolute;
      top: 173%; 
    }
  }
  .insert{
  @include for-phone-only {
    left: 75%;

  }       
    font-family: arial;
    width: 13em;
    height: 6em;
    border: 2px solid $dteal;
    border-bottom: 2px solid #4bc3bc;
    position: absolute;
    border-radius: 7px;
    left: 85%;
    top: 20%;
    transform: translate(-50%,-50%); 
    background:      
      $teal;
    background-repeat: no-repeat;
    &:before{
      content: '';
      width: .8em;
      height: .8em;
      position: absolute;
      top: 30%;
      left: 86%;
      transform: translate(-50%,-50%);
      box-shadow: 0 0 10px #fff, 0 0 20px #fff, 0 0 20px yellowgreen, 0 0 20px yellowgreen, 0 0 30px yellowgreen, 0 0 60px yellowgreen, 0 0 70px yellowgreen;
      background: 
        linear-gradient(
          to top,
          rgba(limegreen,1), rgba(limegreen,1),
        )  
      50% 0% / 100% 100%,           
        ;
      background-repeat: no-repeat;
    }    
    &:after{
      content: '';
      width: 10em;
      height: 1.2em;
      border: 2px solid $dteal;
      position: absolute;
      top: 65%;
      left: 50%;
      transform: translate(-50%,-50%);
      background: 
        linear-gradient(
          to top,
          rgba(#4bc3bc,1), rgba(#19413e,1),
        )  
      50% 0% / 100% 100%,           
        ;
      background-repeat: no-repeat;
    }
    h1{
      font-weight: bolder;
      font-size: 1.5em;
      letter-spacing: 2px;
      text-align: center;
      margin-top: .6em;
    }
    
  }
}

.bk{
  background-image: none;
}

.opacity{
  opacity: .5;
}

              
            
!

JS

              
                var mobile = window.matchMedia('(max-width: 600px)');

var colors = [
'https://assets.codepen.io/2970881/pink_r.png', 'https://assets.codepen.io/2970881/orange_r.png', 'https://assets.codepen.io/2970881/lime_r.png'
]


let soda;
let played ;
var drink = gsap.timeline({paused: true});
function myFunction(x) {
  if (x.matches) {

drink.from('#soda', {
  delay: 1,
  marginTop: '-90',
  ease: 'bounce',
  duration:1
})    

  } else {
drink.from('#soda', {
  delay: 1,
  marginTop: '-150',
  ease: 'bounce',
  duration:1
})    
  }
}

myFunction(mobile)

function ifplayed(){
    if(played){
    // myFunction(mobile)
    drink.restart()
  } else{
    played = true;
    drink.play()
  }
}

$('.stock').click(function(){
  let color = $(this).attr('id');
  if(color == "pink"){
    $('#soda').attr('src', colors[0])
  }
  if(color == "teal"){
    $('#soda').attr('src', colors[1])
  }  
  if(color == "lime"){
    $('#soda').attr('src', colors[2])
  }  
  ifplayed()
 
})

              
            
!
999px

Console