Created
May 29, 2015 23:50
-
-
Save israelcrux/cc5a732065ece92c6109 to your computer and use it in GitHub Desktop.
Snap plugin for showing grids on loaded SVGs
This file contains 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
Snap.plugin( function( Snap, Element, Paper, global ) { | |
Element.prototype.showGrid = function(step) { | |
var w = Math.floor(this.getBBox().width), | |
h = Math.floor(this.getBBox().height); | |
console.log('showing grid step '+step+' '+w+' x '+h); | |
var attrs = { stroke: '#777', 'strokeWidth': 1, 'opacity': 0.7 }; | |
if(this.path){ | |
//horizontal | |
for (var y = 0; y <= h; y+=step) { | |
if(y % 100 == 0) | |
this.path('M0,'+y+'L'+w+','+y).attr({ stroke: '#B77', 'strokeWidth': 2, 'opacity': 0.7 }); | |
else | |
this.path('M0,'+y+'L'+w+','+y).attr(attrs); | |
} | |
//vertical | |
for (var x = 0; x <= w; x+=step) { | |
if(x % 100 == 0) | |
this.path('M'+x+',0L'+x+','+h).attr({ stroke: '#F77', 'strokeWidth': 2, 'opacity': 0.7 }); | |
else | |
this.path('M'+x+',0L'+x+','+h).attr(attrs); | |
} | |
console.log('Grid complete'); | |
} else { | |
console.log('Object is not "gridable"'); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment