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