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.

Details

Privacy

Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO

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.

Template

Make Template?

Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.

Template URL

Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:

Screenshot

Screenshot or Custom Thumbnail

Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO

HTML

              
                <script src="//code.jquery.com/jquery-2.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.2/TweenLite.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.2/utils/Draggable.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.2/plugins/CSSPlugin.min.js"></script>

<div  style="position:absolute;left:0%;top:0%;right:0%;bottom:0%;" class="wrapper">
 
  
  <input class="enablesolution" type="checkbox" style="position:absolute;left:0%;top:0%;height:25px;width:25px;" />
 
  
  <div style="position:absolute;left:35px;top:0px;height:25px;width:150px;"><label style="position:absolute;left:0%;top:50%;height:50%;width:100%;line-height:10%;font-size:15px;">Enable my solution</label></div>

  
  <div  style="position:absolute;left:0%;top:50px;right:0%;bottom:0%;">
    
  <div class="aparent draggable" style="position:absolute;left:0px;top:0px;height:200px;width:200px;background-color:blue;border:1px solid black;">
  
  <div class="achild draggable" style="position:absolute;left:0px;top:0px;height:100px;width:100px;background-color:red;border:1px solid black;"></div>
    
  </div>
</div>
</div>



              
            
!

CSS

              
                
              
            
!

JS

              
                  var presstable = [];

  function pressProcess(e) {
  if($('.enablesolution').is(':checked')){
        var temptarget = $(e.target);
        var templine = temptarget.parent()
        Draggable.get(templine).disable();
        presstable.push([temptarget,templine]);
  }
        return;
    }


    function releaseProcess(e) { 
  if($('.enablesolution').is(':checked')){
        var temptarget = $(e.target);
        var templength = presstable.length;
        var templine = '';
        for (var i = 0; i < templength; i++) {
            templine = presstable[i];
            if (temptarget.get(0) == $(templine[0]).get(0)) {
                Draggable.get($(templine[1])).enable();
                presstable.slice(i, 1);
            }
        }
        }
        return;
    }


  $(function(){
    
    
  Draggable.create(".aparent", {
            type: "x,y", onDragStart: function () { dragStartProcess(this) }, onDragEnd: function () { dragEndProcess(this) }, onPress: function () { pressProcess(this) }, onRelease: function () { releaseProcess(this) }, liveSnap: true,
            snap: {
                x: function (endValue) {
                    return Math.round(endValue / (200)) * (200);
                },
                y: function (endValue) {
                    return Math.round(endValue / (200)) * (200);
                }
            }
        });
    
    
        
        Draggable.create(".achild", { type: "x,y", onDragStart: function () { dragStartProcess(this) }, onDragEnd: function () { dragEndProcess(this) }, onPress: function () { pressProcess(this) }, onRelease: function () { releaseProcess(this) } });
    
    
  });
              
            
!
999px
What's a functional programmer's favorite animal? A lamb, duh!

Console