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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <!-- check the code here https://codepen.io/cartalan/pen/NjPJjj -->
<div class="wrapper">
  <h3>Xylophone - Musical Instrument</h3>
  <div class="container">
    <div class="note note-do1" id="0">
      <div class="screw1 screw1-do1"></div>
      <div class="screw2 screw2-do1"></div>
    </div>
    <div class="note note-re" id="1">
      <div class="screw1 screw1-re"></div>
      <div class="screw2 screw2-re"></div>
    </div>
    <div class="note note-mi" id="2">
      <div class="screw1 screw1-mi"></div>
      <div class="screw2 screw2-mi"></div>
    </div>
    <div class="note note-fa" id="3">
      <div class="screw1 screw1-fa"></div>
      <div class="screw2 screw2-fa"></div>
    </div>
    <div class="note note-sol" id="4">
      <div class="screw1 screw1-sol"></div>
      <div class="screw2 screw2-sol"></div>
    </div>
    <div class="note note-la" id="5">
      <div class="screw1 screw1-la"></div>
      <div class="screw2 screw2-la"></div>
    </div>
    <div class="note note-si" id="6">
      <div class="screw1 screw1-si"></div>
      <div class="screw2 screw2-si"></div>
    </div>
    <div class="note note-do2" id="7">
      <div class="screw1 screw1-do2"></div>
      <div class="screw2 screw2-do2"></div>
    </div>
  </div>
  <div class="bnt-group">
    <div id="btn1" class="btn btn-1"><i class="fa fa-music" aria-hidden="true"></i></div>
    <div id="btn2" class="btn btn-2"><i class="fa fa-music" aria-hidden="true"></i></div>
    <div id="btn3" class="btn btn-3"><i class="fa fa-music" aria-hidden="true"></i></div>
    <div id="btn4" class="btn btn-4"><i class="fa fa-music" aria-hidden="true"></i></div>
    <div id="btn5" class="btn btn-5"><i class="fa fa-music" aria-hidden="true"></i></div>
  </div>  
</div>
<audio src="https://raw.githubusercontent.com/cartalan/Xilofono-Exercise/master/sound/1-DO.mp3" class="sound"></audio>
<audio src="https://raw.githubusercontent.com/cartalan/Xilofono-Exercise/master/sound/2-RE.mp3" class="sound"></audio>
<audio src="https://raw.githubusercontent.com/cartalan/Xilofono-Exercise/master/sound/3-MI.mp3" class="sound"></audio>
<audio src="https://raw.githubusercontent.com/cartalan/Xilofono-Exercise/master/sound/4-FA.mp3" class="sound"></audio>
<audio src="https://raw.githubusercontent.com/cartalan/Xilofono-Exercise/master/sound/5-SOL.mp3" class="sound"></audio>
<audio src="https://raw.githubusercontent.com/cartalan/Xilofono-Exercise/master/sound/6-LA.mp3" class="sound"></audio>
<audio src="https://raw.githubusercontent.com/cartalan/Xilofono-Exercise/master/sound/7-SI.mp3" class="sound"></audio>
<audio src="https://raw.githubusercontent.com/cartalan/Xilofono-Exercise/master/sound/8-DO.mp3" class="sound"></audio>
              
            
!

CSS

              
                @function longShadow($number, $color) {
  $box-shadow: 1px 1px #{$color};
  @for $i from 1 through $number {
    $box-shadow: '#{$box-shadow}, #{$i}px #{$i}px #{$color}'; 
  }
  @return unquote($box-shadow);
}

body {
  background-color: #FCF8E0;
  font-family: 'Raleway', sans-serif;
}

.wrapper {
  // margin-bottom: 302px;
  text-align: center;
}

.container {
  width: 600px;
  height: 300px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 36px 0;
  margin-left: auto;
  margin-right: auto;
  position: relative;
  &:after {
    content: '';
    position: absolute;
    display: flex;
    top: 51%;
    left: -10px;
    width: 625px;
    height: 120px;
    background-color: #574632;
    transform: translateY(-50%);
    border-radius: 3px;
    box-shadow: longShadow(3, darken(#574632, 9));
  }
}

.bnt-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  // align-items: space-between;
  flex-direction: row;
  width: 700px;
  height: 100px;
  margin-left: auto;
  margin-right: auto;
}

.btn {
  display: flex;
  justify-content: center;
  align-items: center;
  color: #2D3235;
  font-weight: normal;
  width: 150px;
  height: 35px;
  background-color: #DAA51E;
  border-radius: 5px;
  box-shadow: longShadow(2, darken(#DAA51E, 20));
  &-1:before {
    content: 'La Cucaracha';
    margin-right: 3px;
  }
  &-2:before {
    content: 'Christmas Carol';
    margin-right: 3px;
  }
  &-3:before {
    content: 'Happy Birthday';
    margin-right: 3px;
  }
  &-4:before {
    content: 'Twinkle Twinkle';
    margin-right: 3px;
  }
   &-5:before {
    content: 'Cielito Lindo';
    margin-right: 3px;
  }
  &:active {
    box-shadow: longShadow(2, darken(#DAA51E, 20)) inset;
    color: lighten(#2D3235, 5);
  }
}

.screw1,.screw2  {
  width: 20px;
  height: 20px;
  background-color: #CCCCCC;
  position: absolute;
  border-radius: 50%;
  box-shadow: longShadow(1, darken(#CCCCCC, 20));
}

.screw1 {
  &-do1 {
    top: 105px;
    &:after {
      content: '|';
      color: darken(#CCCCCC, 20);
      position:absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%) rotate(8deg);
    }
  }
  &-re {
    top: 95px;
    &:after {
      content: '|';
      color: darken(#CCCCCC, 20);
      position:absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%) rotate(54deg);
    }    
  }
  &-mi {
    top: 85px;
    &:after {
      content: '|';
      color: darken(#CCCCCC, 20);
      position:absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%) rotate(48deg);
    }
  }
  &-fa {
    top: 75px;
    &:after {
      content: '|';
      color: darken(#CCCCCC, 20);
      position:absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%) rotate(22deg);
  }
  }
  &-sol {
    top: 65px;
    &:after {
      content: '|';
      color: darken(#CCCCCC, 20);
      position:absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%) rotate(63deg);
    }
  }
  &-la {
    top: 55px;
    &:after {
      content: '|';
      color: darken(#CCCCCC, 20);
      position:absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%) rotate(97deg);
    }
  }
  &-si {
    top: 45px;
    &:after {
      content: '|';
      color: darken(#CCCCCC, 20);
      position:absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%) rotate(17deg);
    }
  }
  &-do2 {
    top: 35px;
    &:after {
      content: '|';
      color: darken(#CCCCCC, 20);
      position:absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%) rotate(38deg);
    }
  }  
}

.screw2 {
  &-do1 {
    top: 175px;
    &:after {
      content: '|';
      color: darken(#CCCCCC, 20);
      position:absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%) rotate(14deg);
    }  
  }
  &-re {
    top: 165px;
    &:after {
      content: '|';
      color: darken(#CCCCCC, 20);
      position:absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%) rotate(27deg);
    }  
  }
  &-mi {
    top: 155px;
    &:after {
      content: '|';
      color: darken(#CCCCCC, 20);
      position:absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%) rotate(4deg);
    }  
  }
  &-fa {
    top: 145px;
    &:after {
      content: '|';
      color: darken(#CCCCCC, 20);
      position:absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%) rotate(38deg);
    }  
  }
  &-sol {
    top: 135px;
    &:after {
      content: '|';
      color: darken(#CCCCCC, 20);
      position:absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%) rotate(56deg);
    }  
  }
  &-la {
    top: 125px;
    &:after {
      content: '|';
      color: darken(#CCCCCC, 20);
      position:absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%) rotate(18deg);
    }  
  }
  &-si {
    top: 115px;
    &:after {
      content: '|';
      color: darken(#CCCCCC, 20);
      position:absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%) rotate(56deg);
    }  
  }
  &-do2 {
    top: 105px;
    &:after {
      content: '|';
      color: darken(#CCCCCC, 20);
      position:absolute;
      top: 0;
      left: 50%;
      transform: translateX(-50%) rotate(84deg);
    }  
  }  
}

.note {
  width: 60px;
  display: flex;
  color: #3a2f21;
  font-weight: normal;
  justify-content: center;
  align-items: center;
  border-radius: 10px;
  position: relative;
  z-index: 10;
  &-do1 {
    background-color: #FF0033;
    height: 300px;
    box-shadow: longShadow(3, darken(#FF0033, 9));
    &:after {
      content: 'DO';
    }
    &:active {
      background-color: darken(#FF0033, 15);
    }
  }
  &-re {
    background-color: #4A4475;
    height: 280px;
    box-shadow: longShadow(3, darken(#4A4475, 9));
    &:after {
      content: 'RE';
    }
    &:active {
      background-color: darken(#4A4475, 15);
    }
  }
  &-mi {
    background-color: #1482A1;
    height: 260px;
    box-shadow: longShadow(3, darken(#1482A1, 9));
    &:after {
      content: 'MI';
    }
    &:active {
      background-color: darken(#1482A1, 15);
    }
  }
  &-fa {
    background-color: #F3A30F;
    height: 240px;
    box-shadow: longShadow(3, darken(#F3A30F, 9));
    &:after {
      content: 'FA';
    }
    &:active {
      background-color: darken(#F3A30F, 15);
    }
  }
  &-sol {
    background-color: #5DD3B1;
    height: 220px;
    box-shadow: longShadow(3, darken(#5DD3B1, 9));
    &:after {
      content: 'SOL';
    }
    &:active {
      background-color: darken(#5DD3B1, 15);
    }
  }
  &-la {
    background-color: #90DBCF;
    height: 200px;
    box-shadow: longShadow(3, darken(#90DBCF, 9));
    &:after {
      content: 'LA';
    }
    &:active {
      background-color: darken(#90DBCF, 15);
    }
  }
  &-si {
    background-color: #FFA4A0;
    height: 180px;
    box-shadow: longShadow(3, darken(#FFA4A0, 9));
    &:after {
      content: 'SI';
    }
    &:active {
      background-color: darken(#FFA4A0, 15);
    }
  }
  &-do2 {
    background-color: #FF404B;
    height: 160px;
    box-shadow: longShadow(3, darken(#FF404B, 9));
    &:after {
      content: 'DO';
    }
    &:active {
      background-color: darken(#FF404B, 15);
    }
  }
}
              
            
!

JS

              
                // do 0
// re 1
// mi 2
// fa 3
// sol 4
// la 5
// si 6
// do+ 7

var notes = $('.sound');

var note1 = [0,0,0,3,5,  0,0,0,3,5,  3,3,2,2,1,1,0,  0,0,0,2,4,  0,0,0,2,4,  7,7,6,5,4,3,1,0];
var tempo1 = [1,1,1,2,3,  1,1,1,2,3,  1,1,1,1,1,1,3,  1,1,1,2,3,  1,1,1,2,3,  2,1,1,1,1,1,1,1];

var note2 = [2,2,2,  2,2,2,  2,4,0,1,2,  3,3,3,  3,2,2,  2,1,1,2,1,4,  2,2,2,  2,2,2,  2,4,0,1,2,  3,3,3,  3,2,2,  4,4,3,1,0];
var tempo2 = [1,1,2,  1,1,2,  1,1,1,1,4,  1,1,2,  1,1,2,  1,1,1,1,2,2,  1,1,2,  1,1,2,  1,1,1,1,4,  1,1,2,  1,1,2,  1,1,1,1,4];

var note3 = [0,0,1,0,3,2,  0,0,1,0,4,3,  0,0,7,5,3,3,2,1,  6,6,5,3,4,3];
var tempo3 = [2,1,2,2,2,3,  2,1,2,2,2,3,  2,1,2,2,2,2,2,3,  2,1,2,2,2,3];

var note4 = [0,0,4,4,5,5,4,5,5,2,2,1,1,0,  4,4,3,3,2,2,1,4,4,3,3,2,2,1,  0,0,4,4,5,5,4,3,3,2,2,1,1,0];
var tempo4 = [2,2,2,2,2,2,4,2,2,2,2,2,2,3,  2,2,2,2,2,2,4,2,2,2,2,2,2,3,  2,2,2,2,2,2,4,2,2,2,2,2,2,3];

var note5 = [7,7,5,6,4,7,7,5,6,4,7,7,6,5,4,3,1,  6,6,5,4,3,1,1,2,3,4,4,3,2,1,0];
var tempo5 =[1,2,1,1,1,1,2,1,1,1,1,2,1,1,1,1,2,  1,2,1,1,1,1,2,1,1,1,2,1,1,1,2];

$('.note').click(function() {
  var num = parseInt(this.id);
  play(num);
});

$('#btn1').click(function() {
  var count = 0;
  for(var i= 0; i < note1.length; i++) {
    setTimeout(function(sound) {
      play(note1[sound]);
    }, rhythm1(i) * 350, i);
  }
});

$('#btn2').click(function() {
  var count = 0;
  for(var i= 0; i < note2.length; i++) {
    setTimeout(function(sound) {
      play(note2[sound]);
    }, rhythm2(i) * 350, i);
  }
});

$('#btn3').click(function() {
  var count = 0;
  for(var i= 0; i < note3.length; i++) {
    setTimeout(function(sound) {
      play(note3[sound]);
    }, rhythm3(i) * 350, i);
  }
});

$('#btn4').click(function() {
  var count = 0;
  for(var i= 0; i < note4.length; i++) {
    setTimeout(function(sound) {
      play(note4[sound]);
    }, rhythm4(i) * 350, i);
  }
});

$('#btn5').click(function() {
  var count = 0;
  for(var i= 0; i < note5.length; i++) {
    setTimeout(function(sound) {
      play(note5[sound]);
    }, rhythm5(i) * 350, i);
  }
});

function play(num) {
  notes[num].pause();
  notes[num].currentTime = 0;
  notes[num].play();
  $("#" + num).css({
    "font-weight": "bold",
    "color": "#FCFBE3"
  });
  setTimeout(function() {
    $("#" + num).css({
      "font-weight": "normal",
      "color": "#3a2f21"
    });
  }, 300);
}

function rhythm1(num) {
  var count = 0;
  for (var i = 0; i < num ; i++) {
    count = count + tempo1[i];
  }
  return count;
}

function rhythm2(num) {
  var count = 0;
  for (var i = 0; i < num ; i++) {
    count = count + tempo2[i];
  }
  return count;
}

function rhythm3(num) {
  var count = 0;
  for (var i = 0; i < num ; i++) {
    count = count + tempo3[i];
  }
  return count;
}

function rhythm4(num) {
  var count = 0;
  for (var i = 0; i < num ; i++) {
    count = count + tempo4[i];
  }
  return count;
}

function rhythm5(num) {
  var count = 0;
  for (var i = 0; i < num ; i++) {
    count = count + tempo5[i];
  }
  return count;
}
              
            
!
999px

Console