Reputation: 157
I have two charts; bar chart and word cloud.
I would like word cloud to move down as I scroll down. Any ideas/examples on how to achieve this with D3.js / JavaScript?
Here is my DEMO
(You should launch the preview in separate window).
Thanks!
Upvotes: 0
Views: 1306
Reputation: 3144
You can control the positioning of a DOM element through a window event listener like this:
window.addEventListener("scroll", myFunc.bind(this, document.getElementById("scroller")), false);
function myFunc(div) {
var scroll = document.body.scrollTop;
div.style.top = (scroll / 10)+"px";
};
So for every ten pixels the user scrolls, the scroller
element will move one pixel.
Cross browser implementation of scrollTop
here
Upvotes: 1