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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


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


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.


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.

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.


                <svg id="demo" xmlns="" width="600" height="200" viewBox="0 0 600 200">
<title>Animate until draggable is released</title>
<rect width="600" height="200" fill="#000"/>
<text fill="white" font-size="16" x="10" y="30" >Spin speed based on x position of draggable element</text>
<rect id="bounds" x="50" y="75" width="350" height="50" fill="white"/>
<g id="dragger"> 	
  <rect x="50" y="75" width="50" height="50" fill="#3088Ef"/>
  <text fill="white" font-size="16" x="75" y="105" text-anchor="middle">DRAG</text>
<g id="spinner">
  <circle cx="500" cy="100" r="50" fill="#3088Ef"/>
  <line x1="500" y1="50" x2="500" y2="75" stroke-width="2" stroke="white"/>
  <circle cx="500" cy="50" r="8" fill="white"/>
  <text fill="white" font-size="16" x="500" y="105" text-anchor="middle">SPIN</text>
<p class="xPos">The dragger x position is: <span>0</span></p>
<p class="rTick">The rotation per tick is: <span>0</span></p>


                body {
  font-family: "Roboto", sans-serif;
  padding: 0;
  margin: 0;

#demo {
  font-family: "Roboto", sans-serif;
  margin: 20px;

p {
  margin: 0;
  font-size: 16px;
  margin-left: 20px;

p span {
  font-weight: 700;



                const xPos = document.querySelector(".xPos span");
const rTick = document.querySelector(".rTick span");
let control = 0; // the x position of the draggable element
TweenMax.set("#spinner", {svgOrigin:"500 100"});

Draggable.create("#dragger", {
	type: "x",
	bounds: "#bounds",
	onDrag: onDrag,
	onPress: onPress,
	onRelease: onRelease

function onDrag() {
	xPos.innerHTML = this.x;
	control = this.x;

function onPress() {
	TweenMax.ticker.addEventListener("tick", spinIt);

function onRelease() {
	TweenMax.ticker.removeEventListener("tick", spinIt);
	xPos.innerHTML = 0;
	rTick.innerHTML = 0;"#dragger", control/1000, {x:0, ease:Power4.easeOut});
	control = 0;

function spinIt() {
	theRotation = control/25;
	rTick.innerHTML = theRotation;
	TweenMax.set("#spinner", {rotation:"+=" + theRotation});