Browse files

Merge pull request #7 from tmcw/location-hash

Hashes for bookmarking
  • Loading branch information...
2 parents 0201947 + 4ecab1b commit a0dc888317244481297893cc39f990bd0bddb0d1 @mbostock committed Mar 19, 2013
Showing with 11 additions and 2 deletions.
  1. +11 −2 stack.v0.js
View
13 stack.v0.js
@@ -45,6 +45,8 @@ var stack = (function() {
.each("end", function() { yTarget = null; self.on("scroll.stack", scroll); });
}
+ location.replace("#" + y1);
+
return stack;
};
@@ -55,10 +57,12 @@ var stack = (function() {
.on("keydown.stack", keydown)
.on("resize.stack", resize)
.on("scroll.stack", scroll)
- .on("mousemove.stack", snap);
+ .on("mousemove.stack", snap)
+ .on("hashchange.stack", hashchange);
resize();
scroll();
+ hashchange();
// if scrolling up, jump to edge of previous slide
function leap(yNew) {
@@ -81,6 +85,11 @@ var stack = (function() {
.style("height", (n - .5) * size + yOffset + "px");
}
+ function hashchange() {
+ var hash = +location.hash.slice(1);
+ if (!isNaN(hash)) stack.position(hash);
+ }
+
function keydown() {
var delta;
switch (d3.event.keyCode) {
@@ -160,7 +169,7 @@ var stack = (function() {
if (y1 > y0 && y1 - y0 < .5 - yOffset / size) scrollTo(0, y1 * size);
// else transition
- else stack.position(y1);
+ else if (y1 !== y0) stack.position(y1);
}
function tween(y) {

0 comments on commit a0dc888

Please sign in to comment.