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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <p>Arrastre los trazados.</p>
<svg width="350" height="350" viewBox="0 0 350 350">
              body {
  background-color: #333;
  color: #d9d9d9;
  font-family: Arial, sans-serif;
  text-align: center;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 200%;

svg {
  border: 1px solid #777;
  display: block;
  margin: 20px auto;
svg *{cursor:move;}
              var SVG_NS = 'http://www.w3.org/2000/svg';
var svg = document.querySelector("svg");
var oTrazados = []; 
var svgRaton = {x:0, y:0};// la posición del ratón relativo al lienzo SVG
var arrastrar = false;

var trazados = [
  {att:{cx:225, cy:175, rx:70,ry:50,fill:"#2a80b9"},
  {att:{points:"134,128 209,288 59,288",fill:"#f1c40f"},
  {att:{d:"M135,220C135,175 170,125 205,140C240,155 210,225 190,225C180,225 180,205 160,205C150,205 147,225 142,225C140,225 135,225 135,220Z", fill:"#8f44ad"},nombreEtiqueta:"path"}

function oMousePos(elemento, evt) {
  var ClientRect = elemento.getBoundingClientRect();
  return { //objeto
    x: Math.round(evt.clientX - ClientRect.left),
    y: Math.round(evt.clientY - ClientRect.top)

function Trazado() {
  this.att = {};
  this.rectRaton = {x:0, y:0};// la posición del ratón relativo al trazado
  this.distInicial = {x:0, y:0};// la posición inicial del trazado
  this.nombreEtiqueta = "";
  this.dibujar = function(elementoPadre) {
    var elmt = document.createElementNS(SVG_NS, this.nombreEtiqueta);
    for (var name in this.att) {
      if (this.att.hasOwnProperty(name)) {
        elmt.setAttributeNS(null, name, this.att[name]);
    this.elemento = elmt;
  this.actualizar = function(x,y){
    this.elemento.setAttributeNS(null, "transform", "translate("+x+","+y+")");
}//function Trazado()

for( var i = 0; i < trazados.length; i++ ){
  //crea un nuevo objeto Trazado
  var oTrazado = new Trazado();
  // establece los atributos del nuevo trazado
  oTrazado.att = trazados[i].att;
  // y el nombre de la etiqueta: rect, ellipse....
  oTrazado.nombreEtiqueta = trazados[i].nombreEtiqueta;  
  // dibuja el nuevo trazado
  // lo guarda en el array de los trazados: oTrazados

  var t = svg.querySelectorAll("*");

for(var n = 0; n < t.length; n++){
    (function(n) {
     var num = 0;// un contador
     t[n].addEventListener("mousedown", function(evt){
       svgRaton = oMousePos(svg, evt); 
       oTrazados[n].rectRaton = oMousePos(this, evt);
       if(num == 1){// calculado solo una vez, en el primer clic encima del trazado.
       // recupera la posición inicial del trazado
       oTrazados[n].distInicial.x = svgRaton.x - oTrazados[n].rectRaton.x;
       oTrazados[n].distInicial.y = svgRaton.y - oTrazados[n].rectRaton.y;
       arrastrar = true;
     }, false);
     t[n].addEventListener("mousemove", function(evt) {
       if (arrastrar) {
        svgRaton = oMousePos(svg, evt);
         var x = svgRaton.x - oTrazados[n].rectRaton.x - oTrazados[n].distInicial.x;
         var y = svgRaton.y - oTrazados[n].rectRaton.y - oTrazados[n].distInicial.y;
        oTrazados[n].actualizar( x, y);  
       }, false);
       t[n].addEventListener("mouseup", function(evt) {
       arrastrar = false;
       }, false);

       t[n].addEventListener("mouseout", function(evt) {
       arrastrar = false;
       }, false); 
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.