1 | define(["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: |
---|
7 | // Returns an animation that will smooth-scroll to a node |
---|
8 | // description: |
---|
9 | // This implementation support either horizontal or vertical scroll, as well as |
---|
10 | // both. In addition, element in iframe can be scrolled to correctly. |
---|
11 | // args: |
---|
12 | // - offset: {x: int, y: int} this will be added to the target position |
---|
13 | // - duration: Duration of the animation in milliseconds. |
---|
14 | // - win: a node or window object to scroll |
---|
15 | |
---|
16 | if(!args.target){ args.target = domGeom.position(args.node); } |
---|
17 | |
---|
18 | var isWindow = lang[(has("ie") ? "isObject" : "isFunction")](args["win"].scrollTo), |
---|
19 | delta = { x: args.target.x, y: args.target.y } |
---|
20 | ; |
---|
21 | if(!isWindow){ |
---|
22 | var winPos = domGeom.position(args.win); |
---|
23 | delta.x -= winPos.x; |
---|
24 | delta.y -= winPos.y; |
---|
25 | } |
---|
26 | var _anim = (isWindow) ? |
---|
27 | (function(val){ |
---|
28 | args.win.scrollTo(val[0],val[1]); |
---|
29 | }) : |
---|
30 | (function(val){ |
---|
31 | args.win.scrollLeft = val[0]; |
---|
32 | args.win.scrollTop = val[1]; |
---|
33 | }); |
---|
34 | var anim = new baseFx.Animation(lang.mixin({ |
---|
35 | beforeBegin: function(){ |
---|
36 | if(this.curve){ delete this.curve; } |
---|
37 | var current = isWindow ? dojo._docScroll() : {x: args.win.scrollLeft, y: args.win.scrollTop}; |
---|
38 | anim.curve = new Line([current.x,current.y],[current.x + delta.x, current.y + delta.y]); |
---|
39 | }, |
---|
40 | onAnimate: _anim |
---|
41 | },args)); |
---|
42 | return anim; // dojo.Animation |
---|
43 | }; |
---|
44 | fx.smoothScroll = fxExt.smoothScroll; |
---|
45 | return fxExt.smoothScroll; |
---|
46 | }); |
---|