forked from vvo/in-viewport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom-container-with-offset.js
97 lines (79 loc) · 2.35 KB
/
custom-container-with-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
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
93
94
95
96
97
describe('using offsets with a div as a reference container', function() {
require('./fixtures/bootstrap.js');
beforeEach(h.clean);
afterEach(h.clean);
var test;
var container;
var calls;
var width = 500;
var position = 1000;
var offset = 200;
beforeEach(function() {
calls = [];
test = h.createTest({
style: {
left: position + 'px',
top: position + 'px'
}
});
container = h.createTest({
attributes: {
id: 'container'
},
style: {
width: width + 'px',
height: width + 'px',
overflow: 'scroll'
}
});
container.innerHTML = '<div class="scrollTrigger"></div>';
h.insertTest(test, container);
h.insertTest(container);
inViewport(test, {
container: container,
offset: offset
}, cb);
});
describe('when we scroll down on body', function() {
beforeEach(h.scroller(position, position));
it('cb not called', function() {
assert.strictEqual(calls.length, 0);
});
});
describe('when we scroll inside the container', function() {
describe('before the element', function () {
var scrollBefore = position - width - offset - 2;
beforeEach(h.scroller(100, 100, 'container'));
beforeEach(h.scroller(scrollBefore, scrollBefore, 'container'));
it('cb not called', function() {
assert.strictEqual(calls.length, 0);
});
});
describe('too far after the element', function() {
var scrollFarAfter = 2 * position;
beforeEach(h.scroller(scrollFarAfter, scrollFarAfter, 'container'));
it('cb not called', function() {
assert.strictEqual(calls.length, 0);
});
});
describe('to the element', function() {
var scrollToTheElement = position - width;
beforeEach(h.scroller(scrollToTheElement, scrollToTheElement, 'container'));
beforeEach(h.wait(50));
it('cb was called', function() {
assert.strictEqual(calls.length, 1);
});
});
describe('in the offset range', function() {
var scrollInTheOffset = position - width - offset;
beforeEach(h.scroller(scrollInTheOffset, scrollInTheOffset, 'container'));
beforeEach(h.wait(50));
it('cb was called', function() {
assert.strictEqual(calls.length, 1);
});
});
});
function cb(result) {
calls.push(result);
}
});