6
|
1 define([ 'dojo/on', 'dojo/dom-geometry', 'dojo/dom-style' ], function(on, g,
|
|
2 css) {
|
|
3
|
|
4 return function(sticker, options) {
|
|
5 var dh, pos;
|
|
6
|
|
7 var pos = g.position(sticker,true);
|
|
8
|
|
9 var origLeft = css.get(sticker,'left');
|
|
10 var left = pos.x + 'px';
|
|
11
|
|
12 if (options && options.along) {
|
|
13 var along = g.position(options.along,true);
|
|
14 dh = along.y + along.h - pos.h - pos.y;
|
|
15 } else {
|
|
16 dh = window.scrollMaxY - pos.h - pos.y;
|
|
17 }
|
|
18
|
|
19 var fixed = false;
|
|
20
|
|
21 var stfn = function() {
|
|
22 if(!options || !options.along)
|
|
23 dh = window.scrollMaxY - pos.h - pos.y;
|
|
24
|
|
25 if (window.scrollY >= pos.y && window.scrollY <= pos.y + dh) {
|
|
26 if (!fixed) {
|
|
27 css.set(sticker, { top : 0, left: left, position : 'fixed' });
|
|
28 fixed = true;
|
|
29 }
|
|
30 } else {
|
|
31 if (fixed) {
|
|
32 fixed = false;
|
|
33
|
|
34 css.set(sticker, { position : 'relative', left: origLeft });
|
|
35
|
|
36 if (window.scrollY < pos.y) {
|
|
37 css.set(sticker, { top : 'auto' });
|
|
38 } else {
|
|
39 css.set(sticker, { top : dh + 'px' });
|
|
40 }
|
|
41 }
|
|
42 }
|
|
43 };
|
|
44
|
|
45 stfn();
|
|
46
|
|
47 on(window, 'scroll', stfn );
|
|
48 };
|
|
49 }); |