dmotz / oriDomi

🪭 Fold up DOM elements like paper
https://oxism.com/oriDomi
MIT License
2.41k stars 207 forks source link

Trigger OriDomi to scroll #32

Closed BeatLaG closed 10 years ago

BeatLaG commented 10 years ago

Hi!

I´m trying to found a method to handle oriDomi triggered to the scroll event but I can´t figure out how to do this properly. Could you give me some advice in this line? I mean, I´m trying to trigger the scroll up/down with the plugin´s dragging features. Which would be the easiest way to achieve this? Any help will be very grateful :)

Many thanks!

dmotz commented 10 years ago

I would create an OriDomi instance and initialize its speed to 0 ({ speed: 0 }) so the folding rate is 1 to 1 with the scrolling (unless you do scroll rate throttling).

Then just attach the folding behavior to a scroll listener, e.g.

window.addEventListener('scroll', function() {
   oridomi.accordion(window.pageYOffset / 5);
}, false);

This should get you started but you'll want to tweak that math and maybe throttle the rate.

BeatLaG commented 10 years ago

It works perfectly. Thank you very much!

This plugin is simply amazing :)