forked from vvo/in-viewport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hidden-element.js
44 lines (38 loc) · 1.08 KB
/
hidden-element.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
var supportsMutationObserver = typeof global.MutationObserver === 'function';
if (supportsMutationObserver) {
describe('asking if a hidden div is in the viewport', function() {
require('./fixtures/bootstrap.js');
beforeEach(h.clean);
afterEach(h.clean);
var visible = false;
var test;
beforeEach(function() {
test = h.createTest({
style: {
width: '500px',
height: '500px',
display: 'none'
}
});
h.insertTest(test);
inViewport(test, function() {
visible = true;
});
});
// scrolling down and up, should not call the callback: element is not visible
beforeEach(h.scroller(0, 100));
beforeEach(h.scroller(0, 0));
it('callback not called', function() {
assert(visible === false);
});
describe('when element becomes visible', function(done) {
beforeEach(function(done) {
test.style.display = 'block';
setTimeout(done, 40);
});
it('callback called', function() {
assert(visible === true);
});
});
});
}