cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

            
              <!-- Created by Bennett Feely. -->

<!-- This demo uses Velocity.js in lieu of Cytoscape.js because the demo already existed using it and it uses the same spring force parameters for animation. Cheers to the Velocity guys! -->

<main>
  <h1>Spring Physics and Cytoscape.js</h1>
  <section>
    <span>[<div class="tension" contenteditable>500</div>, <div class="friction" contenteditable>20</div>]</span>
    <button>Run</button>
    <small>[tension, friction]</small></section>
  	<br>
    <div id="box"></div>
    <br>
  <pre><code>ele.animate({
  { position: { x: 300 } }
}, { 
  duration: 625,
  easing: 'spring(<b id="code_tension">tension</b>, <b id="code_friction">friction</b>)'
});</code></pre>  
</main>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Source+Code+Pro:300,400,500,600,700);

$radius : .5rem;

body {
  font-family: "Source Code pro", monospace;
  background: whitesmoke;
}

h1 {
  text-transform: uppercase;
  font-size: 1.4rem;
  font-weight: 300;
}

main {
  width: 30rem;
  margin: 0 auto;
}

section {
  text-align: left;
  position: relative;
  display: inline-block;
  background: white;
  padding: .75rem 1rem;
  padding-right: 5rem;
  font-size: 2em;
  font-family: monospace;
  border-radius: .5rem;
  box-shadow: 0 .125rem lightgray;
  overflow: hidden;
}

small {
  display: block;
  font-size: .8rem;
  margin-top: 1em;
  padding-bottom: .25rem;
  transition: .3s;

  section:hover & {
    color: black;
  }
}

[contenteditable] {
  display: inline-block;
  text-align: center;
  min-width: 1em;
  border: 0;
  background: white;
  border-radius: $radius;
  transition: .3s;
  vertical-align: -10%;
  
  span:hover & {
    background: #ffa;
  }
  
  &:focus,
  section:hover &:focus {
    outline: 0;
    background: yellow;
    padding: 0 .25em;
  }
}

button {
  display: inline-block;
  position: absolute;
  top: 0;
  right: 0;
  border: 0;
  background: lightgreen;
  padding: .25em .5em;
  border-top-right-radius: $radius;
  box-shadow: inset 0 -.125rem rgba(0,0,0,.1);
  transition: .4s;
  transform-origin: top right;
  
  &:hover {
    background: darken(lightgreen, 20%);
    transition: .2s;
  }
  &:active {
    transform: scale(1.1);
    transition: 0;
  }
  &:focus {
    outline: 0;
  }
}

#box {
  width: 100px;
  height: 100px;
  margin-top: 1em;
  transform-origin: 0 0;
  background: darkgray;
  border-radius: 100px;
  position: relative;
}

pre {
  display: inline-block;
  font-size: .9rem;
  text-align: left;
  background: rgba(black, .05);
  margin-top: 1rem;
  padding: 1.5rem 2rem;
  border-radius: $radius;
  box-shadow: inset 0 .125rem gainsboro;
}
            
          
!
            
              var $box = $("#box");

$("button").click(spring);

function spring() {
  var tension = $(".tension").text(),
      friction = $(".friction").text();
  
  $box
    .velocity({
      left: "300px"  
    }, 625, [tension, friction])
    .velocity("reverse");
  
  $("#code_tension").text(tension);
  $("#code_friction").text(friction);
}
            
          
!
999px
🕑 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.
Loading ..................

Console