comparison public_html/static/js/implab/sticky.js @ 6:2d1a0a75fc49

added css, templates
author sergey
date Mon, 12 May 2014 18:05:30 +0400
parents
children d9551c7e7101
comparison
equal deleted inserted replaced
5:0b703449f192 6:2d1a0a75fc49
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 });