Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <div class="outerWrapper" id="outerWrapper">

	<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" enable-background="new 0 0 800 300" xml:space="preserve">
		 
		<path id="path" d="M30,30 L770,30" />
		<path id="path1" d="m 113.05501,53.784728 138.98015,-3.741772 c 12.19063,0.998499 23.37882,12.334291 5.61266,24.588796 l -31.00326,11.492589 c -14.16529,7.044979 -28.33057,4.324702 -42.49586,3.207234 -10.8316,-2.557966 -22.68938,-7.326158 -24.58879,9.35443 1.38536,20.115295 -23.96567,20.692455 -39.28862,28.597835 -12.35061,2.52357 -28.872661,17.31612 -29.93419,-13.36347 1.33595,-8.41924 4.030187,-15.989545 22.18337,-13.89802 8.37029,3.80826 16.85021,5.86247 25.92515,-1.603605 8.38066,-7.781896 7.91989,-13.599029 -2.93997,-17.105254 L 87.664404,83.451647 C 68.151266,82.3964 70.34726,94.815787 70.826424,106.16955 75.629934,135.6352 61.310633,139.76312 37.685003,131.56015 23.062667,123.98051 8.215213,116.78358 7.483548,85.589804 12.765525,66.21072 26.621231,55.71157 51.850288,56.991962 Z"/>

		<ellipse cx="15" cy="15" rx="10" ry="10" id="drag"
  style="fill:yellow;stroke:purple;stroke-width:2" />

		<ellipse cx="15" cy="15" rx="10" ry="10" id="drag1"
  style="fill:yellow;stroke:purple;stroke-width:2" />

	</svg>
       
</div>
              
            
!

CSS

              
                body {
  margin: 0;
  background: #565279;
}

.outerWrapper {
	width: 800px;
	height: 300px;
	position: relative;
}

.outerWrapper svg {
	position: absolute;
}

.outerWrapper svg path {
	fill:none; 
	stroke:#DABDD8;
	stroke-width:5; 
	stroke-dasharray:0;
}

.outerWrapper svg polygon {
	fill:orange; 
}
              
            
!

JS

              
                /*	A variable to keep track of where we are on the line
	0 = start, 1 = end */
var counter = 0;

/*	A boolean variable to keep track of the direction we want to travel in 
	true = move to the left, false move to the right */
var direction = true;

/*	First get a reference to the enclosing div and then to
	the 2 svg paths */
var svgContainer = document.getElementById("outerWrapper");
var ns = "http://www.w3.org/2000/svg";
var svg = svgContainer.getElementsByTagNameNS(ns, "path");
/*	the var 'svg' contains a reference to two paths so svg.length = 2
	svg[0] is the straight line and svg[1] is the curved lines */

/*	Now get the length of those two paths */
var straightLength = svg[0].getTotalLength();
var curveLength = svg[1].getTotalLength();

/*	Also get a reference to the two star polygons */
var stars = svgContainer.getElementsByTagName("ellipse");



function moveStar() {
	/*	Check to see where the stars are journeys to determine 
		what direction they should be travelling in */
	if (parseInt(counter,0) === 1) {
		/* we've hit the end! */
		direction = false;
	} else if (parseInt(counter,0) < 0) {
		/* we're back at the start! */
		direction = true;
	}

	/*	Based on the direction variable either increase or decrease the counter */
  
TweenLite.set(drag, {
  transformOrigin: 'center',
  rotation: startAngle + '_rad',
  xPercent: 0,
  yPercent: 0,
  x: startPoint.x,
  y: startPoint.y
})

var draggable = new Draggable(drag, {
  liveSnap: {
    points: pointModifier
  }
})

// TweenLite.set('.container', {
//   autoAlpha: 1
// })
	// if (direction) {
	// 	counter += 0.003;
	// } else {
	// 	counter -= 0.003;
	// }

	/*	Now the magic part. We are able to call .getPointAtLength on the tow paths to return 
		the coordinates at any point along their lengths. We then simply set the stars to be positioned 
		at these coordinates, incrementing along the lengths of the paths */
	stars[0].setAttribute("transform","translate("+ (svg[0].getPointAtLength(counter * straightLength).x -15)  + "," + (svg[0].getPointAtLength(counter * straightLength).y -15) + ")");
	stars[1].setAttribute("transform","translate("+ (svg[1].getPointAtLength(counter * curveLength).x -15)  + "," + (svg[1].getPointAtLength(counter * curveLength).y -15) + ")");

	/*	Use requestAnimationFrame to recursively call moveStar() 60 times a second
		to create the illusion of movement */
  stars.draggable();
	requestAnimationFrame(moveStar);
}
requestAnimationFrame(moveStar);


              
            
!
999px

Console