root / trunk / src / lfx / scroll.js

Revision 6507, 1.7 kB (checked in by liucougar, 4 years ago)

dojo.require("dojo.lfx.Animation") is enough instead of dojo.lfx.*

shouldn't dojo.lfx.Animation be dojo.lfx.animation instead?

  • Property svn:eol-style set to native
Line 
1dojo.provide("dojo.lfx.scroll");
2dojo.require("dojo.html.util");
3dojo.require("dojo.html.iframe");
4dojo.require("dojo.lfx.Animation");
5
6dojo.lfx.smoothScroll = function(/*DOMNode*/ node,
7                                                                                        /*Window*/ win,
8                                                                                        /*Object*/offset,
9                                                                                        /*int?*/ duration,
10                                                                                        /*function?*/ easing,
11                                                                                        /*Object?*/ handlers){
12        // summary: Returns an animation that will smooth-scroll to a node (specified in setup())
13        // description: This implementation support either horizental or vertical scroll, as well as
14        //              both. In addition, element in iframe can be scrolled to correctly.
15        // offset: {x: int, y: int} this will be added to the target position
16        // duration: Duration of the animation in milliseconds.
17        // easing: An easing function.
18        // handlers: { handler: Function?, onstart: Function?, onstop: Function?, onanimate: Function? }
19
20        var targs = {
21                "window": win,
22                "offset": offset || {x:0,y:0},
23                "target": dojo.html.getAbsolutePositionExt(node,true,dojo.html.boxSizing.BORDER_BOX, win),
24                "duration": duration,
25                "easing": easing||dojo.lfx.easeOut
26        };
27
28        var anim = new dojo.lfx.Animation({
29                        beforeBegin: function(){
30                                var current = dojo.withGlobal(targs.window,dojo.html.getScroll).offset;
31                                delete this.curve;
32                                anim.curve = new dojo.lfx.Line([current.x,current.y],[targs.target.x+targs.offset.x,targs.target.y+targs.offset.y]);
33                        },
34                        onAnimate: function(value){
35                                targs.window.scrollTo(value[0],value[1]);
36                        }
37                },
38                duration, 
39                null, //curve, will be set in scrollTo
40                easing||dojo.lfx.easeOut
41        );
42        if(handlers){
43                for(var x in handlers){
44                        if(dojo.lang.isFunction(handlers[x])){
45                                anim.connect(x, anim, handlers[x]);
46                        }
47                }
48        }
49
50        return anim; // dojo.lfx.Animation
51}
Note: See TracBrowser for help on using the browser.