forked from vvo/in-viewport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
offset.js
67 lines (52 loc) · 1.57 KB
/
offset.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
describe('using offsets', function() {
require('./fixtures/bootstrap.js');
beforeEach(h.clean);
afterEach(h.clean);
function testElemOffset(x, y, offset) {
describe(offset+' offset with an element at '+x+','+y, function() {
var test;
var calls;
// at this scroll position, element should be shown
var scrollTo = y -
document.documentElement.clientHeight -
offset + 1;
beforeEach(h.clean);
beforeEach(function() {
calls = [];
test = h.createTest({
style: {
width: '1px',
height: '1px',
left: x + 'px',
top: y + 'px'
}
});
h.insertTest(test);
inViewport(test, { offset: offset }, cb);
});
describe('when we scroll 100px before the offset', function() {
beforeEach(h.scroller(0, scrollTo - 100));
it('cb not called', function() {
assert.strictEqual(calls.length, 0);
});
});
describe('when we scroll 20px before the offset', function() {
beforeEach(h.scroller(0, scrollTo - 20));
it('cb no called', function() {
assert.strictEqual(calls.length, 0);
});
});
describe('when we scroll down at the exact position', function() {
beforeEach(h.scroller(0, scrollTo));
it('cb called', function() {
assert.strictEqual(calls.length, 1);
});
});
function cb(result) {
calls.push(result);
}
});
}
testElemOffset(0, 10000, 200);
testElemOffset(0, 10000, 1500);
});