Skip to content

Instantly share code, notes, and snippets.

@MrHuli
Created September 13, 2017 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrHuli/ad8f6575cfa29e92b9b4eedec37a4b0f to your computer and use it in GitHub Desktop.
Save MrHuli/ad8f6575cfa29e92b9b4eedec37a4b0f to your computer and use it in GitHub Desktop.
drawLine : function( x1, y1, x2, y2 ) {
var x = x1 - x2,
y = y1 - y2,
length = Math.sqrt( ( x * x ) + ( y * y ) ),
angle  = Math.atan2( y2 - y1, x2 - x1 ) * 180 / Math.PI, 
transform = 'rotate(' + angle + 'deg)';
var line = $( '<div>' )
.appendTo( 'body' )
.css( {
'position' : 'absolute',
'transform' : transform,
'left' : x1,
'top' : y1
} )
.width( length );
return line;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment