forked from vvo/in-viewport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom-container.js
92 lines (73 loc) · 2.08 KB
/
custom-container.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
describe('using a div as a reference container', function() {
require('./fixtures/bootstrap.js');
beforeEach(h.clean);
afterEach(h.clean);
var test;
var container;
var calls;
beforeEach(function() {
calls = [];
test = h.createTest({
style: {
left: '1000px',
top: '1000px'
}
});
container = h.createTest({
attributes: {
id: 'container'
},
style: {
width: '500px',
height: '500px',
overflow: 'scroll'
}
});
container.innerHTML = '<div class="scrollTrigger"></div>';
h.insertTest(test, container);
h.insertTest(container);
inViewport(test, {
container: container
}, cb);
});
describe('when we scroll down on body', function() {
beforeEach(h.scroller(1000, 1000));
it('cb not called', function() {
assert.strictEqual(calls.length, 0);
});
});
describe('when we scroll inside the container', function() {
describe('before the div', function () {
beforeEach(h.scroller(100, 100, 'container'));
it('cb not called', function() {
assert.strictEqual(calls.length, 0);
});
});
describe('too far after the div', function() {
beforeEach(h.scroller(10000, 10000, 'container'));
it('cb not called', function() {
assert.strictEqual(calls.length, 0);
});
});
describe('to the element', function() {
beforeEach(h.scroller(1000, 1000, 'container'));
beforeEach(h.scroller(1005, 1005, 'container'));
beforeEach(h.wait(50));
it('cb was called', function() {
assert.strictEqual(calls.length, 1);
});
});
describe('when we scroll down, up, like crazy', function() {
beforeEach(h.scroller(0, 200, 'container'));
beforeEach(h.scroller(0, 1000, 'container'));
beforeEach(h.scroller(0, 20000, 'container'));
beforeEach(h.scroller(1000, 1000, 'container'));
it('cb was called once', function() {
assert.strictEqual(calls.length, 1);
});
});
});
function cb(result) {
calls.push(result);
}
});