I’m trying to use jQuery.scrollTo plugin with accordion (where one block expands after clicking on it and another contracts), but it doesn’t scroll to the right position.
Here is a demo: pelmeshkin.com/temp/scrolltoaccoridon
As you can see, the first click scrolls correctly, but every next one goes further than it should.
It seems to use target’s initial position (where it was before the expansion/contraction), which makes sense, since both events are initiated at the same time, but even when I try to pause scrollTo and wait until the slideUp/slideDown transition is over, it still behaves the same. 🙁
Ok, I sort of solved it myself. I first find positions of all clickable elements on pageload using offset(), put them in array, and then feed these as pixel values to scrollTo on click event.
This way we’re giving scrollTo exact pixel positions to scroll to on the page, rather than relying on it to calculate it from element ID by itself. Here’s how it looks in the end: pelmeshkin.com