Last active
November 12, 2015 21:16
-
-
Save spektraldevelopment/e88feff4884c4658d37a to your computer and use it in GitHub Desktop.
JS: CreateLine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var | |
| coordinates = [{ | |
| 'x': 149, | |
| 'y': 163 | |
| }, { | |
| 'x': 338, | |
| 'y': 110 | |
| }, { | |
| 'x': 690, | |
| 'y': 47 | |
| }, { | |
| 'x': 933, | |
| 'y': 123 | |
| }, { | |
| 'x': 1243, | |
| 'y': 187 | |
| }]; | |
| function createLine(posObj, callback) { | |
| var | |
| length = Math.sqrt((posObj['x1'] - posObj['x2']) * (posObj['x1'] - posObj['x2']) + (posObj['y1'] - posObj['y2']) * (posObj['y1'] - posObj['y2'])), | |
| angle = Math.atan2(posObj['y2'] - posObj['y1'], posObj['x2'] - posObj['x1']) * 180 / Math.PI, | |
| transform = 'transform: rotate(' + angle + 'deg)', | |
| lineStyle = "left:" + posObj['x1'] + "px; top: " + posObj['y1'] + "px; transform: rotate(" + angle + "deg);", | |
| line; | |
| line = createElement(mainContainer, 'div', { | |
| 'className': 'line', | |
| 'style': lineStyle | |
| }); | |
| TweenLite.to(line, speed, { | |
| width: length + 'px', | |
| onComplete: function() { | |
| callback(); | |
| } | |
| }); | |
| } | |
| //Example | |
| createLine({ | |
| 'x1': coordinates[0]['x'], | |
| 'y1': coordinates[0]['y'], | |
| 'x2': coordinates[1]['x'], | |
| 'y2': coordinates[1]['y'] | |
| }, gotoFrameTwo); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #main-container { | |
| position: absolute; | |
| width: 1500px; | |
| height: 250px; | |
| } | |
| div.line { | |
| transform-origin: 0 100%; | |
| position: absolute; | |
| background-color: #ff6600; | |
| width: 0; | |
| height: 2px; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is for drawing lines from one point to another. Much like the Indiana Jones map effect.