scroll the document?

10 views
Skip to first unread message

clarkk

unread,
May 8, 2011, 5:31:58 PM5/8/11
to scripty2
Hi

How can you scroll the whole document?

I have tried a couple of solutions but without any luck

document.body.scrollTo(300, {
transition: 'easeInOutQuad',
duration: 0.5
});

window.scrollTo(300, {
transition: 'easeInOutQuad',
duration: 0.5
});

$(document.body).scrollTo(300, {
transition: 'easeInOutQuad',
duration: 0.5
});

but the morph() method works fine like this

div.morph('opacity:0; filter:aplha(opacity=0)', {
transition: 'easeInOutQuad',
delay: 2,
duration: 1
});

Rod

unread,
May 8, 2011, 7:46:30 PM5/8/11
to scripty2

I've had problems with this myself and spent a bit too much time
working it out. Scrolling is a special case since you're operating on
the parent document and not a simple DOM element, there is special
handling in S2 that overrides Prototype's default scrollTo() but it
doesn't seem to work properly. The solution I ended up with was to use
an attribute animator like this:

new S2.FX.Attribute(window, document.viewport.getScrollOffsets().top,
element.getLayout().get('top'), { duration: 0.4 }, function(t)
{ window.scrollTo(0, t.round()) }).play().start()

2nd argument is current scroll position, 3rd argument is where we want
to scroll to (could be a fixed number like in your example), and last
argument is the animator frame function that'll handle each time
point.

The .play().start() construct at the end is odd but I had a lot of
trouble getting the the animator state to work properly with
S2.FX.Attribute and this does the trick.

Chers,
Rod
Reply all
Reply to author
Forward
0 new messages