cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <div id="bm_animation">

</div>

<svg class="bg" viewBox="0 0 1518 1084" preserveAspectRatio="xMinYMax slice"><defs><style>.cls-1{fill:none;}.cls-2{clip-path:url(#clip-path);}.cls-11,.cls-3{fill:#242014;}.cls-10,.cls-11,.cls-12,.cls-3,.cls-4,.cls-5,.cls-6,.cls-8{stroke:#161616;}.cls-3,.cls-4,.cls-5,.cls-8{stroke-miterlimit:10;}.cls-10,.cls-11,.cls-12,.cls-3,.cls-4,.cls-5,.cls-6,.cls-7,.cls-8{stroke-width:8px;}.cls-4{fill:#312d24;}.cls-5{fill:#595d69;}.cls-6,.cls-7{fill:#1e1508;}.cls-10,.cls-11,.cls-12,.cls-6,.cls-7{stroke-linejoin:round;}.cls-7{stroke:#131216;}.cls-8{fill:#1d1a14;}.cls-9{fill:#563a0f;}.cls-10{fill:#36332b;}.cls-12{fill:#272314;}.cls-13{fill:#760000;animation: blink-animation 2s steps(5, start) infinite;}</style><clipPath id="clip-path" transform="translate(4 4)"><rect class="cls-1" width="1510" height="1080"/></clipPath></defs><g class="cls-2"><rect class="cls-3" x="4" y="4" width="1510" height="681"/><line class="cls-4" x1="4" y1="478" x2="1514" y2="478"/><line class="cls-4" x1="1514" y1="604" x2="4" y2="604"/><rect class="cls-4" x="1072.54" y="488.36" width="264.82" height="84"/><polyline class="cls-4" points="1514 572.36 1373.18 572.36 1373.18 488.36 1514 488.36"/><rect class="cls-4" x="771.91" y="488.36" width="264.82" height="84"/><rect class="cls-4" x="471.27" y="488.36" width="264.82" height="84"/><rect class="cls-4" x="170.64" y="488.36" width="264.82" height="84"/><line class="cls-4" x1="1514" y1="594.76" x2="4" y2="594.76"/><line class="cls-4" x1="4" y1="572.42" x2="1514" y2="572.42"/><rect class="cls-5" x="302.42" y="8.36" width="288.62" height="469.64"/><polyline class="cls-4" points="4 488.36 134.82 488.36 134.82 572.36 4 572.36"/><polygon class="cls-4" points="277.76 9.2 277.76 595 320.41 595 382.85 9.2 277.76 9.2"/><polygon class="cls-4" points="309.28 9.2 295.42 595 312.48 595 351.33 9.2 309.28 9.2"/><polygon class="cls-4" points="625 9.2 625 595 582.35 595 519.91 9.2 625 9.2"/><polygon class="cls-4" points="593.48 9.2 607.34 595 590.28 595 551.43 9.2 593.48 9.2"/><path class="cls-4" d="M304.94,2.68s47.29,75.06,137.79,75.06S587,2.68,587,2.68Z" transform="translate(4 4)"/><path class="cls-4" d="M312.28,2S357.1,51.13,442.89,51.13,579.7,2,579.7,2Z" transform="translate(4 4)"/><path class="cls-4" d="M324.51,2s40.73,27.3,118.67,27.3S567.47,2,567.47,2Z" transform="translate(4 4)"/><rect class="cls-6" x="867.88" y="268" width="167.24" height="111"/><rect class="cls-7" x="878.24" y="278.36" width="146.52" height="91.27"/><polyline class="cls-8" points="933.99 318.32 920.17 328.19 917.71 367.65 949.77 367.65 946.81 321.77"/><polyline class="cls-8" points="950.27 312.89 950.27 328.19 947.8 367.65 979.87 367.65 972.96 320.29 963.59 309.93"/><polyline class="cls-8" points="907.35 318.32 893.53 328.19 891.07 367.65 923.13 367.65 920.17 321.77"/><ellipse class="cls-3" cx="912.28" cy="312.65" rx="9.87" ry="11.1"/><ellipse class="cls-3" cx="940.4" cy="317.09" rx="6.91" ry="7.77"/><ellipse class="cls-3" cx="956.68" cy="309.19" rx="6.91" ry="7.77"/><ellipse class="cls-3" cx="960.63" cy="327.94" rx="6.91" ry="7.77"/><line class="cls-9" x1="4" y1="604" x2="1514" y2="604"/><line class="cls-9" x1="1514" y1="1083" x2="4" y2="1083"/><rect class="cls-9" x="4" y="611" width="1510" height="473"/></g><polygon class="cls-10" points="159.73 622.3 332.21 612.98 291.27 597.82 138.61 608.13 159.73 622.3"/><polygon class="cls-11" points="165.36 655.24 338.07 645.32 332.21 612.98 159.73 622.3 165.36 655.24"/><polygon class="cls-12" points="138.59 607.76 159.49 622.9 165.36 655.24 140.46 640.33 138.59 607.76"/><polygon class="cls-13" points="175.2 638.38 173.98 639.75 174.37 646.21 175.74 647.42 176.86 646.17 176.46 639.39 175.2 638.38"/><polygon class="cls-13" points="174.62 628.48 173.4 629.85 173.78 636.31 175.15 637.52 176.27 636.27 175.87 629.49 174.62 628.48"/><polygon class="cls-13" points="182.78 637.93 181.56 639.3 181.94 645.75 183.31 646.97 184.43 645.71 184.03 638.93 182.78 637.93"/><polygon class="cls-13" points="175.93 647.79 177.3 649 181.85 648.73 183.07 647.36 181.81 646.25 176.94 646.54 175.93 647.79"/><polygon class="cls-13" points="175.34 637.89
 176.71 639.1 181.26 638.83 182.48 637.46 181.22 636.35 176.35 636.64 175.34 637.89"/><polygon class="cls-13" points="174.75 627.99 176.13 629.2 180.67 628.93 181.89 627.56 180.63 626.45 175.76 626.74 174.75 627.99"/><polygon class="cls-13" points="188.19 637.6 186.96 638.97 187.35 645.43 188.72 646.64 189.84 645.38 189.44 638.6 188.19 637.6"/><polygon class="cls-13" points="187.6 627.7 186.38 629.07 186.76 635.52 188.14 636.74 189.25 635.48 188.85 628.7 187.6 627.7"/><polygon class="cls-13" points="195.17 627.24 193.95 628.61 194.33 635.07 195.71 636.28 196.83 635.02 196.43 628.25 195.17 627.24"/><polygon class="cls-13" points="195.76 637.14 194.54 638.51 194.92 644.97 196.3 646.18 197.42 644.93 197.01 638.15 195.76 637.14"/><polygon class="cls-13" points="188.91 647.01 190.28 648.22 194.83 647.95 196.05 646.58 194.79 645.46 189.92 645.76 188.91 647.01"/><polygon class="cls-13" points="187.73 627.2 189.11 628.42 193.65 628.14 194.87 626.77 193.61 625.66 188.74 625.96 187.73 627.2"/><polygon class="cls-13" points="202.68 636.72 201.46 638.09 201.85 644.55 203.22 645.76 204.34 644.51 203.94 637.73 202.68 636.72"/><polygon class="cls-13" points="202.1 626.82 200.87 628.19 201.26 634.65 202.63 635.86 203.75 634.61 203.35 627.83 202.1 626.82"/><polygon class="cls-13" points="198.79 629.61 197.56 630.98 197.62 631.85 198.99 633.06 200.11 631.8 200.04 630.62 198.79 629.61"/><polygon class="cls-13" points="199.36 639.3 198.14 640.67 198.19 641.53 199.57 642.74 200.69 641.49 200.62 640.3 199.36 639.3"/><polygon class="cls-13" points="209.67 626.36 208.45 627.73 208.83 634.19 210.2 635.4 211.32 634.15 210.92 627.37 209.67 626.36"/><polygon class="cls-13" points="210.26 636.27 209.03 637.64 209.42 644.09 210.79 645.31 211.91 644.05 211.51 637.27 210.26 636.27"/><polygon class="cls-13" points="203.4 646.13 204.78 647.34 209.32 647.07 210.54 645.7 209.28 644.59 204.42 644.88 203.4 646.13"/><polygon class="cls-13" points="202.23 626.33 203.6 627.54 208.15 627.27 209.37 625.9 208.11 624.78 203.24 625.08 202.23 626.33"/><polygon class="cls-13" points="215.67 635.94 214.44 637.31 214.83 643.77 216.2 644.98 217.32 643.72 216.92 636.94 215.67 635.94"/><polygon class="cls-13" points="215.08 626.04 213.86 627.41 214.24 633.87 215.61 635.08 216.73 633.82 216.33 627.04 215.08 626.04"/><polygon class="cls-13" points="222.65 625.58 221.43 626.95 221.81 633.41 223.19 634.62 224.31 633.36 223.9 626.58 222.65 625.58"/><polygon class="cls-13" points="223.24 635.48 222.02 636.85 222.4 643.31 223.77 644.52 224.89 643.27 224.49 636.49 223.24 635.48"/><polygon class="cls-13" points="216.39 645.35 217.76 646.56 222.3 646.28 223.53 644.91 222.27 643.8 217.4 644.1 216.39 645.35"/><polygon class="cls-13" points="215.21 625.54 216.58 626.76 221.13 626.48 222.35 625.11 221.09 624 216.22 624.29 215.21 625.54"/></svg>
            
          
!
            
              body, html{
 margin:0;
 width:100%;
 height:100%;
background-color: #563A0F;
 overflow: hidden;
}

#bm_animation{
  position: relative;
  height: 100%;
  width: 100%;
  overflow: hidden;
  cursor: pointer;
  z-index: 10;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0); 
}

.bg{
  position: absolute;
  margin: auto;
  height: 100%;
  width:100%;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 0;
}

.blink {
  animation: blink-animation 2s steps(5, start) infinite;
}
@keyframes blink-animation {
  to {
    visibility: hidden;
  }
}



            
          
!
            
              let sound = new Howl({
  src: ['https://s3-us-west-2.amazonaws.com/s.cdpn.io/304639/codevember8sprite.mp3'],
  sprite: {
   whatuwant: [0, 7130],
   introbg: [16166, 24429, true],
   main: [42446, 42170, true],
   hit: [7226, 271],
   hit2: [7606, 344],
   finalblow: [8235, 1500]
  }
});

let bgmId;

Howler.volume(0.5);

const container = document.getElementById("bm_animation");
const animData = {
  container: container,
  renderer: "svg",
  loop: true,
  prerender: false,
  autoplay: true,
  autoloadSegments: false,
  path: "https://jorisvanraaij.nl/codepen/fridge_fight/js/fridge-data.json"
};

let anim;
let dmgCounter = 0;
let segments = [
  [[150, 169], [170, 179]], 
  [[180, 194], [195, 204]],
  [[205, 218], [219, 228]],
  [[229, 234], [235, 244]],
  [[245, 255], [256, 265]],
  [[266, 271], [272, 281]],
  [[282, 295], [296, 306]],
  [[306, 320], [321, 330]],
  [[331, 425], [426, 435]],
  [[436, 495], [170, 179]],
];
let isHitting = false;

anim = bodymovin.loadAnimation(animData);
anim.addEventListener("DOMLoaded", startAnimation);
bm_animation.onclick = hit;

const init = () => {
  sound.once("load", function() {
    startAnimation();
  });
};

function hitComplete() {
  dmgCounter++;
  isHitting = false;
  anim.removeEventListener("loopComplete", hitComplete);
}

function hit() {
  if (isHitting) {
    return;
  }
    
  if (dmgCounter === 0) {
    sound.stop(bgmId);
    bgmId = sound.play('main');
  }
  
  if (dmgCounter >= segments.length) {
    dmgCounter = 1;
  }
  
  sound.play('hit');
  
  isHitting = true;
  
  anim.playSegments([segments[dmgCounter][0], segments[dmgCounter][1]], true);
  
  console.log(dmgCounter);
  
  if(dmgCounter == 8){sound.play('finalblow');}
  anim.addEventListener("loopComplete", hitComplete);
}

function startAnimation() {
  bgmId = sound.play('introbg');
  sound.play('whatuwant');
  anim.playSegments([[0, 49], [50, 149]], true);
}
            
          
!
999px
Loading ..................

Console