Login Register

smoothScroll animation in dojo.lfx

Sometime ago, someone asked about smoothscroll support in dojo. While working on index list of Editor2, I found myself in the position of requiring such a mechanism, so that rather than jumping to an element, scrolling smoothly to the element gives user a better feeling of context.

Rather than implementing a widget directly, as asked for in the linked post, a dojo.lfx animation shall be created first. Although the core of the smoothScroll is simple to figure out, I had little knowledge about the dojo.lfx code base. After inspecting dojo.lfx.html.propertyAnimation and resource dojo.lfx.Animation, I got the idea of what the animation framework dojo.lfx provides.

After implemented with the help of the great dojo.lfx infrustrature, the code for the smoothScroll turns out to be not complex at all. However, with this tiny code, both horizental and vertical smooth scrolling is supported. In addition, scrolling to nodes in iframes are well implemented.

Checkout the scoll test page for how to use it. In the test page, it also demostrates how to chain animation together to obtain some cool eye candies, check it out.

Along with this new dojo.lfx resource, other improvements include:

  • dojo.html.getAbsolutePosition is extended to be compatible with dojo.withGlobal
  • a new function, dojo.html.getAbsolutePositionExt is introduced in resource dojo.html.util to include support for getting abosolute postion of a node in iframes with regards to a given window. The reason why this is not merged into dojo.html.getAbsolutePosition is that, this new feature depends on APIs defined in dojo.html.util. In order to avoid introducing it as a dependency in dojo.html.layout, this design decision is made.

Alas, the "scroll test page"

Alas, the "scroll test page" link is giving me a 404.

Thank you for documenting

Thank you for documenting your design decision. Most people just write what they did (I can see that in the code), not why they did it!

try now the nightly is

try now the nightly is updated daily

Hey Cougar, Should the

Hey Cougar, Should the "this text is green" be red? ;) Just curious if there is maybe some other underlying stuff I that isnt obvious just by looking at the test page (not at the src). -Karl

hehe, I just made use of an

hehe, I just made use of an iframe content from another test and did not bother to write a new one. So you can ignore those bogus text in there :)

Hmmm... I can't get it to

Hmmm... I can't get it to work at all in Opera 9.02. I'm guessing this error (which happens on page load) is the root of the problem: JavaScript - javascript:'dojo.html.createExternalElement=function(doc, tag){ return doc.createElement(tag); }' Linked script not loaded This results in, I believe, the following error, which probably means that either node or getBoundingClientRect() is undefined, and if stuff wasn't loaded, that makes sense: Type mismatch... with (node.getBoundingClientRect()) I don't really have time to do any other investigation right now (deadlines are too close), but thought I'd let you know.

it does work for me in opera

it does work for me in opera 9.02 (linux) without javascript error however, opera does have some issues with this: it seems it can only scroll down, not scroll up, has to look into this

It does not work on Safari,

It does not work on Safari, see: http://dojotoolkit.org/node/713