Created
March 3, 2015 20:12
-
-
Save tonyfast/5b462f9545dacbe61b37 to your computer and use it in GitHub Desktop.
crop image with svg shape using d3
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
| <!doctype html> | |
| <html> | |
| <head> | |
| <script src='//cdn.jsdelivr.net/g/d3js'></script> | |
| </head> | |
| <body> | |
| <svg width="700" height="660"> | |
| <defs> | |
| <pattern id="image" x="0" y="0" patternUnits="userSpaceOnUse" height="200" width="200"> | |
| <image x="0" y="0" height="200" width="200" xlink:href="http://lorempixel.com/100/100" type="image/png"></image> | |
| </pattern> | |
| <pattern id="image2" x="0" y="0" patternUnits="userSpaceOnUse" height="100" width="100"> | |
| <image x="0" y="0" height="200" width="200" xlink:href="http://lorempixel.com/100/100" type="image/png"></image> | |
| </pattern> | |
| </defs> | |
| <circle id='top' cx="80" cy="80" r="80" fill="url(#image)" fill-opacity=".6"/> | |
| <circle id='top' cx="240" cy="80" r="80" fill="url(#image2)"/> | |
| </svg> | |
| <script> | |
| ;( function(){ | |
| d3.select( 'circle' ) | |
| .on( 'mouseenter', function(){ | |
| d3.select(this) | |
| .attr( 'fill-opacity',1) | |
| }) | |
| .on( 'mouseleave', function(){ | |
| d3.select(this) | |
| .transition( ) | |
| .ease('cubic') | |
| .duration( 1000 ) | |
| .attr( 'fill-opacity',.6) | |
| }) | |
| .on( 'click', function(d,i){ | |
| // go somewhere | |
| }) | |
| })(); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment