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="inputDiv">
<!--El valor del panControl es un número decimal entre -1 y 1 -->
<p><input id="panControl" type="range" min="-1" max="1" value="0.5" step="0.01"  /></p>
</div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body{background:#333; height:100vh;}
p{color:#777; text-align:center;line-height:150%; margin-bottom:1em; }

.inputDiv {
  width: 250px;
  margin: 50vh auto;
  position: relative;
}

input[type='range'] {
  display: block;
  width: 250px;
}

input[type='range']:focus {
  outline: none;
}

input[type='range'],
input[type='range']::-webkit-slider-runnable-track,
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
}

input[type=range]::-webkit-slider-thumb {
  background-color: #777;
  width: 20px;
  height: 20px;
  border: 3px solid #333;
  border-radius: 50%;
  margin-top: -9px;
}

input[type=range]::-moz-range-thumb {
  background-color: #777;
  width: 15px;
  height: 15px;
  border: 3px solid #333;
  border-radius: 50%;
}

input[type=range]::-ms-thumb {
  background-color: #777;
  width: 20px;
  height: 20px;
  border: 3px solid #333;
  border-radius: 50%;
}

input[type=range]::-webkit-slider-runnable-track {
  background-color: #777;
  height: 3px;
}

input[type=range]:focus::-webkit-slider-runnable-track {
  outline: none;
}

input[type=range]::-moz-range-track {
  background-color: #777;
  height: 3px;
}

input[type=range]::-ms-track {
  background-color: #777;
  height: 3px;
}

input[type=range]::-ms-fill-lower {
  background-color: HotPink
}

input[type=range]::-ms-fill-upper {
  background-color: black;
} 

              
            
!

JS

              
                var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
// crea un nuevo nodo audio panner
var pan = audioCtx.createStereoPanner(audioCtx);
// crea un nuevo oscildor, 
// lo conecta con el panner y 
// conecta el panner con los dispositivos de salida
crearOscilador();


// al arrastrar el boton del slider
panControl.addEventListener("input", function() {
// el balance cambia hacia la derecha o hacia la izquierda
  pan.pan.value = this.value;
});

// inicia el oscilador al presionar el botón del ratón 
panControl.addEventListener("mousedown", function() {
    crearOscilador();
    oscilador.start();
});
// para el oscilador al soltar el botón del ratón
panControl.addEventListener("mouseup", function() {
    oscilador.stop();
});


function crearOscilador() {
  // crea un nuevo oscilador
  oscilador = audioCtx.createOscillator();
  // establece la frequencia del oscilador
  oscilador.frequency.value = 100;
  // conecta el oscilador con el panner
  oscilador.connect(pan);
  // y el panner con los dispositivos de destino
  pan.connect(audioCtx.destination);
}

              
            
!
999px

Console