source: Dev/branches/rest-dojo-ui/client/dojox/fx/scroll.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.7 KB
Line 
1define(["dojo/_base/kernel","dojo/_base/lang", "dojo/_base/fx", "dojox/fx/_base","dojox/fx/_core","dojo/dom-geometry","dojo/_base/sniff"],
2        function (kernel, lang, baseFx, fxExt, Line, domGeom, has){
3        kernel.experimental("dojox.fx.scroll");
4        var fx = lang.getObject("dojox.fx",true);
5        fxExt.smoothScroll = function(/* Object */args){
6                // summary: Returns an animation that will smooth-scroll to a node
7                // description: This implementation support either horizontal or vertical scroll, as well as
8                // both. In addition, element in iframe can be scrolled to correctly.
9                // offset: {x: int, y: int} this will be added to the target position
10                // duration: Duration of the animation in milliseconds.
11                // win: a node or window object to scroll
12       
13                if(!args.target){ args.target = domGeom.position(args.node); }
14       
15                var isWindow = lang[(has("ie") ? "isObject" : "isFunction")](args["win"].scrollTo),
16                        delta = { x: args.target.x, y: args.target.y }
17                ;
18                if(!isWindow){
19                        var winPos = domGeom.position(args.win);
20                        delta.x -= winPos.x;
21                        delta.y -= winPos.y;
22                }
23                var _anim = (isWindow) ?
24                        (function(val){
25                                args.win.scrollTo(val[0],val[1]);
26                        }) :
27                        (function(val){
28                                args.win.scrollLeft = val[0];
29                                args.win.scrollTop = val[1];
30                        });
31                var anim = new baseFx.Animation(lang.mixin({
32                        beforeBegin: function(){
33                                if(this.curve){ delete this.curve; }
34                                var current = isWindow ? dojo._docScroll() : {x: args.win.scrollLeft, y: args.win.scrollTop};
35                                anim.curve = new Line([current.x,current.y],[current.x + delta.x, current.y + delta.y]);
36                        },
37                        onAnimate: _anim
38                },args));
39                return anim; // dojo.Animation
40        };
41        fx.smoothScroll = fxExt.smoothScroll;
42        return fxExt.smoothScroll;
43});
Note: See TracBrowser for help on using the repository browser.