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.

            
              <ul class="swinger"></ul>

            
          
!
            
              @import compass

html
  background: black
body
  margin: 0
  padding: 0
.swinger
  width: 1px
  height: 0px
  margin: 0 auto
  position: relative
  min-height: 400px
li
  position: absolute
  top: 10px
  left: 50%
  width: 1px
  height: 1px
  list-style: none
  animation: swing alternate infinite ease-in-out

.string
  display: block
  width: 1px
  background-color: rgba(255,255,255,.3)

.ball
  display: block
  width: 25px
  height: 25px
  +border-radius(30px)
  +background(radial-gradient(rgb(187, 181, 199), rgb(115, 115, 116) 70%) -3px -5px)
  border: 1px solid #c8c8c8
  content: ' '
  position: relative
  +box-shadow(0 2px 2px 1px rgba(0,0,0,.2), -2px -2px 4px 3px rgba(0,0,0,.1) inset)

@keyframes swing
  from
    +transform(rotate(-25deg))
  to
    +transform(rotate(25deg))
            
          
!
            
              var swinger = $(".swinger");

// Insert DOM
for (var i = 0; i < 15; i++) {
  var stringContainer = document.createElement('li');
  var string          = document.createElement('span');
  var ball            = document.createElement('span');
  stringContainer.className = 'no' + i;
  string.className          = "string";
  ball.className            = "ball";
  swinger.append(stringContainer);
  $(stringContainer).append(string, ball); 
}

var g        = 9.8; // gravity
var maxOsc  = 15;   // number of oscillations the longest pendulum performs in the cycle
var duration = 240; // duration of one cycle in seconds

// Calculate string heights
var height = [];
for (var j = 0; j < 15; j++) {
  var length   = g * duration / Math.pow((2 * Math.PI * (maxOsc + j)), 2); // equation to calculate string lengths for harmonic wave pendulum
  height.push(length);
}
height.reverse();
 
var sizeCoeff = 150;
// Use harmonic pendulum equation to animate
var elements = $("li");
for (var k = 0; k < 15; k++) {
  var that = elements[k];
  var time = 2 * Math.PI * Math.sqrt(height[k] / g); // harmonic wave pendulum equation
  var size = sizeCoeff * height[k];
  $(".string", that).height(size * 10); // magic numbers for string length in px
  $(".ball", that)
    .height(size)
    .width(size)
    .css('left', (-1/2) * size);
  $(that).attr("style", "animation-duration: " + time + "s;");
};
            
          
!
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