Skip to content

Instantly share code, notes, and snippets.

@lordliquid
Created March 2, 2018 18:59
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 lordliquid/616d13dcdd2741b97b6f5ff783d2d83a to your computer and use it in GitHub Desktop.
Save lordliquid/616d13dcdd2741b97b6f5ff783d2d83a to your computer and use it in GitHub Desktop.
Menu
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
// Feel free to change or delete any of the code you see in this editor!
var svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", '100%')
let toolbar = svg.append('g');
let links = ['Home', 'Menu Item 1', 'Menu Item 2', 'Menu Item 3'];
function expandToolbar() {
let elem = d3.select(this);
elem
.transition()
.duration(1000)
.ease(d3.easeCircleOut)
.attr('width', '20%')
.attr('height', '100%')
.attr('z-index', 1);
let textEnter = elem.selectAll('text')
.data(links)
textEnter
.enter()
.append('text')
.text(t => t)
.attr('fill', 'white')
.attr('z-index', 1000)
}
function collapseToolbar() {
let elem = d3.select(this);
elem
.transition()
.duration(700)
.ease(d3.easeCircleIn)
.attr('width', '2%')
.attr('height', '100%');
}
toolbar
.append('rect')
.attr('width', '2%')
.attr('height', '100%')
.on('mouseover', expandToolbar)
.on('mouseout', collapseToolbar)
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment