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.

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.

HTML

              
                <div>
	<button id="btn1">Toggle Tween</button>
</div>


<div class="path-container">
	<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
		 width="800px" height="300px" viewBox="0 0 800 300" style="enable-background:new 0 0 800 300;" xml:space="preserve">
	<path style="fill:none;stroke:#000000;stroke-miterlimit:10;" d="M0,0c0,0,14,184,157,184V86h173c0,0,105-3,105,93"/>
	</svg>

	<div id="div1">1</div>
</div>

<div id="logDiv"></div>
              
            
!

CSS

              
                body
{
	margin:0;
}

button{
	padding:10px;
	border-radius: 10px;
}

#div1
{
	width:50px;
	height:50px;
	top:0;
	left:0;
	position:absolute;
	background:#00f;
	font:bold 20px "Trebuchet MS", Arial, Helvetica, sans-serif;
	text-align:center;
	color:#fff;
	line-height:50px;
	z-index:100;
}

#logDiv
{
	position:relative;
	margin-top: 20px;
	border:solid 2px;
	width:90%;
	margin-left:5%;
	padding:10px;
}

.path-container
{
	position: relative;
	margin: 10px;
}
              
            
!

JS

              
                var pathString = "M0,0c0,0,14,184,157,184V86h173c0,0,105-3,105,93";

var arrayPath = [];

// Snap SVG method to create a set of cubic bezier curves from the path string
var newPath = Snap.path.toCubic(pathString);

function setUpPoint(segment){

	//using +=2 in the loop thanks to GSAP's Geek Ambassador, animation superhero Carl Schooff :D
	for(var i = 0; i < segment.length; i+=2){

		//create a new object for the point so it can be passed into the bezier plugin
		var point = {};

		point.x = segment[i];
		point.y = segment[i+1];

		//add the point to the array
		arrayPath.push(point);

		$("#logDiv").append("{x:" + point.x +"y:" + point.y + "}, ");
	}//loop end
}

// loop through the curves collection
for(var i = 0; i < newPath.length; i++){
	var segment = newPath[i],
			point;

	// the first element returned in the array is a letter, quite useless for the bezier Plugin, so we remove it
	segment.shift();

	//call the function to set up the points based on the segment returned	
	point = setUpPoint(segment);
}





/** STANDARD GSAP STUFF **/

var t = TweenMax.to("#div1", 3, {
	bezier:{
		type:"cubic",
		values:arrayPath
	},
	force3D:true,paused:true,ease:Linear.easeNone
}).reversed(true);


$("#btn1").click(function(e){
	t.reversed() ? t.play() : t.reverse();
});
              
            
!
999px

Console