- SVG button (this one)
- styling uses: gradient fill & drop shadow
- buttons interact by dispatching custom events
- Toggling buttons
- SVG drop-shadow
- For animations, I prefer mbostock's block
- An HTML button
Last active
July 9, 2021 02:28
-
-
Save pbogden/7487564 to your computer and use it in GitHub Desktop.
SVG button
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<title>button</title> | |
<body> | |
<style> | |
body { | |
font-family: Univers, Arial, sans-serif; | |
} | |
.button rect { | |
stroke: #999faa; /* navy 40% */ | |
stroke-width: 2px; | |
} | |
.button rect.pressed { | |
fill: #000f2b; /* navy 100% */ | |
} | |
.button #gradient-start { | |
stop-color: #999faa; /* navy 40% */ | |
stop-opacity: 1; | |
} | |
.button #gradient-stop { | |
stop-color: #4d576b; /* navy 70% */ | |
stop-opacity: 1; | |
} | |
.button #gradient-start.active, .button #gradient-start.pressed { | |
stop-color: #4d576b; /* navy 70% */ | |
} | |
.button #gradient-stop.active, .button #gradient-stop.pressed { | |
stop-color: #000f2b; /* navy 100% */ | |
} | |
.button text { | |
font-size: 30px; | |
fill: #eee; | |
pointer-events: none; | |
text-anchor: middle; | |
-moz-user-select: none; | |
-webkit-user-select: none; | |
-ms-user-select: none; | |
} | |
</style> | |
<body> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="d3.button.js"></script> | |
<script> | |
var width = 960, height = 500; | |
var data = [{label: "Click me", x: width / 4, y: height / 4 }, | |
{label: "Click me too", x: width / 2, y: height / 2 }]; | |
var svg = d3.select('body').append('svg') | |
.attr('width', width) | |
.attr('height', height); | |
var button = d3.button() | |
.on('press', function(d, i) { console.log("Pressed", d, i, this.parentNode)}) | |
.on('release', function(d, i) { console.log("Released", d, i, this.parentNode)}); | |
// Add buttons | |
var buttons = svg.selectAll('.button') | |
.data(data) | |
.enter() | |
.append('g') | |
.attr('class', 'button') | |
.call(button); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment