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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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
Loading ..................

Console