jiahuang / d3-timeline

Simple JS timeline plugin for d3
1.04k stars 280 forks source link

Added ability to trigger a function on scroll #5

Closed ghost closed 11 years ago

ghost commented 11 years ago

I wanted to display the current year of the leftmost date as a hovering text tag above the timeline. I added a scroll function that takes a callback that gets called when the timeline is scrolled. The callback gets passed the scale-corrected leftmost visible x-axis point and the x-axis scale object. In my case I just called "scale.invert(x).getFullYear()," but one could just as easily use the provided parameters to grab dates at any fixed point relative to the timeline's visible window (as demonstrated in example.html).