1 |
|
2 |
|
3 | El.$b.topFloat = function(el, offset) {
|
4 | var h = el.offsetHeight + offset
|
5 | , lastAbs = 0
|
6 | , lastTop = 0
|
7 | , toFix = 0
|
8 |
|
9 | El.on(window, "scroll", function() {
|
10 | var pos
|
11 | , top = El.scrollTop()
|
12 |
|
13 |
|
14 | if (top < lastTop) {
|
15 | if (top <= toFix) {
|
16 | el.style.position = "fixed"
|
17 | el.style.top = toFix = 0
|
18 | } else {
|
19 | pos = lastTop - h
|
20 | if (toFix < 0 || lastAbs < pos) {
|
21 | el.style.position = "absolute"
|
22 | el.style.top = (lastAbs = toFix = pos < 0 ? 0 : pos < lastAbs ? lastAbs : pos) + "px"
|
23 | }
|
24 | }
|
25 | } else if (toFix === 0) {
|
26 | el.style.position = "absolute"
|
27 | el.style.top = lastTop + "px"
|
28 | lastAbs = lastTop
|
29 | toFix = -1
|
30 | }
|
31 | lastTop = top
|
32 | })
|
33 | }
|
34 |
|
35 |
|
36 |
|