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="example">

<code class="pAR_out">preserveAspectRatio="<span id="pAR_out_target">none</span>"</code>
<div id="pAR_interactive_container" class="pAR_interactive_resizeable">
    <a href="#" id="pAR_resize_handle"></a>
    <!-- width: 400px height: 240px -->
    <svg version="1.1" id="pAR_interactive" width="100%" height="100%">
        <rect x="0" y="0" width="100%" height="100%" fill="#aaaaff"/>
        <svg version="1.1" id="pAR_interactive2" viewBox="0 0 180 240" width="100%" height="100%" preserveAspectRatio="none" >
            <rect width="180" height="240" fill="#666666"/>
            <circle cx="90" cy="120" r="60" fill="yellow" stroke="red" stroke-width="2"/>
            <circle cx="68" cy="105" r="14" fill="black"/>
            <circle cx="112" cy="105" r="14" fill="black"/>
            <path d="M 50 140 A 50 50 0 0 0 130 140" fill="black" stroke="none"/>
        </svg>
    </svg>
</div>

<div class="pAR_controls">
    <h3>"align":</h3>
    <ul class="pAR_X">
        <li><a data-val="xMinYMin" data-type="update_X" href="#">xMinYMin</a></li><li><a data-val="xMidYMin" data-type="update_X" href="#">xMidYMin</a></li><li><a data-val="xMaxYMin" data-type="update_X" href="#">xMaxYMin</a></li><li><a data-val="xMinYMid" data-type="update_X" href="#">xMinYMid</a></li><li><a data-val="xMidYMid" data-type="update_X" href="#">xMidYMid</a></li><li><a data-val="xMaxYMid" data-type="update_X" href="#">xMaxYMid</a></li><li><a data-val="xMinYMax" data-type="update_X" href="#">xMinYMax</a></li><li><a data-val="xMidYMax" data-type="update_X" href="#">xMidYMax</a></li><li><a data-val="xMaxYMax" data-type="update_X" href="#">xMaxYMax</a></li>
    </ul>
    <h3>"meetOrSlice":</h3>
    <ul class="pAR_Z">
        <li><a data-val="meet" data-type="update_Z" href="#">meet</a></li><li><a data-val="slice" data-type="update_Z" href="#">slice</a></li>
    </ul>
    <h3>Don't preserve Aspect Ratio:</h3>
    <ul class="pAR_Z">
        <li><a data-val="none" data-type="update_Z" class="active" href="#">none</a></li>
    </ul>
</div>
</div>

<!--<small>Example 5 - SVGs render differently depending on the value of preserveAspectRatio.</small> -->
              
            
!

CSS

              
                .example{
    text-align: center;
}
.pAR_controls{
    margin-bottom: 0;
    h3{
      margin: 0;
      font-size: 1em;
  }
}
.pAR_out{
    background: #ccc;
    padding: 10px;
    display: block;
    font-size: 1.2em;
    margin-bottom: 20px;
    
    span{
      color: blue;
    }
}
.pAR_controls{
  
    @media screen and (min-width: 600px){
      width: 70%;
      margin: 0 auto;
    }
  
    ul, li{
      margin: 0;
      padding: 0;
      list-style: none;
    }
    ul{
      margin-bottom: 10px;
    }
    li{
      display: inline-block;
      width: 32%;
      margin: 0.5%;
    }
    a{
      background: #ffffff;
      border: 1px solid #2244cc;
      display: block;
      padding: 6px 20px;
      color: #2244cc;
      margin: 0;
      
      &:hover{
        color: #ff0000;
        border: 1px solid #ff0000;
      } 

      &.active{
        color: #ffffff;
        background: #2244cc;
        border: none;
      }
    }  
}

#pAR_interactive_container{
    width: 200px;
    height: 160px;
    margin: 0 auto 20px auto;
    position: relative;
    border: 1px solid #ff8f35;
}

#pAR_resize_handle{
    display: block;
    background: #ff8f35;
    width: 20px;
    height: 20px;
    position: absolute;
    bottom: -20px;
    right: -20px;
    /*border: 1px solid #ff0000;*/
    -moz-border-radius: 0 50% 50% 50%;
    -webkit-border-radius: 0 50% 50% 50%;
    border-radius: 0 50% 50% 50%;
    z-index: 100;
}

small{
  display: block;
  text-align: center;
  margin: 0 auto;
  padding: 20px;
  width: 50%;
}
              
            
!

JS

              
                //updates the svg preserveAspectRatio property
$(function(){

    var $target  = $( "#pAR_interactive2" ),
        x_string = "", //xMin, xMid, xMax
        z_string = "", //meet, slice, none - if none, x_string === ""

        methods = {
            update_X : function( $this ){

                $( ".pAR_X" ).find( "a" ).removeClass( "active" );
                x_string = "";

                if( $this !== undefined ){

                    x_string = $this.data( "val" ) + " ";
                    $this.addClass( "active" );

                    if( z_string === "none" || z_string === "" ){

                        methods.update_Z( $( $( ".pAR_Z" ).find( "a" )[ 0 ] ) );
                    }
                }
            },
            update_Z : function( $this ){
                $( ".pAR_Z" ).find( "a" ).removeClass( "active" );
                z_string = "";

                if( $this !== undefined ){

                    z_string = $this.data( "val" );
                    $this.addClass( "active" );
                }

                if( z_string === "none" ){
                    methods.update_X( undefined );
                }
                else if( x_string === "" ){
                    methods.update_X( $( $( ".pAR_X" ).find( "a" )[ 0 ] ) );
                }
            },
            updatePAR : function(){

                var str = x_string + z_string,
                    pAR_i = document.getElementById( "pAR_interactive2" );

                $( "#pAR_out_target" ).text( str );
                pAR_i.setAttribute( "preserveAspectRatio", str );
            }
        };

    $( ".pAR_controls" ).delegate( "a", "click", function( e ){

        var $this = $( this );

        methods[ $this.data( "type" ) ]( $this );
        methods.updatePAR();
        return false;
    } );
});

//makes the SVG resizable and the drag handle draggable
$(function(){

    var $handle    = $( "#pAR_resize_handle" ),
        $container = $( "#pAR_interactive_container" ),

        startMouseMove = function( $dW, $dH ){

            $( document ).on( "mousemove.pAR", function( event ){

                var $cO   = $container.offset();
                    $eW   = event.pageX - $cO.left,
                    $eH   = event.pageY - $cO.top,
                    reset = false;
                
                //min size for resizing
                if( $eW < 20 ){ $eW = 20; }
                if( $eH < 20 ){ $eH = 20; }
              
                //max size for resizing
                if( $eW >= 300 ){ $eW = 300; }
                if( $eH >= 300 ){ $eH = 300; }

                $container.width( $eW - $dW );
                $container.height( $eH - $dH );
            } );
        },
        stopMouseMove = function(){
            $( document ).off( "mousemove.pAR" );
        };

    //start dragging
    $handle.on( "mousedown", function( event ){

        var $cO = $container.offset(),
            $dW = event.pageX - $cO.left - $container.width(),
            $dH = event.pageY - $cO.top  - $container.height();

        startMouseMove( $dW, $dH );
        return false;
    } );

    //stop default action
    $handle.on( "click", function( event ){
        return false;
    } );

    //stop dragging
    $( document ).on( "mouseup", function( event ){

        stopMouseMove();
        return false;
    } );
});
              
            
!
999px

Console