-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcover.js
41 lines (35 loc) · 1.19 KB
/
cover.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
var coverGuide = function(cover, target) {
var body = document.body, doc = document.documentElement;
var targetWidth = target.clientWidth,
targetHeight = target.clientHeight;
var pageWidth=doc.scrollWidth,
pageHeight=doc.scrollHeight;
// offset of target
var offsetTop = target.getBoundingClientRect().top
offsetLeft = target.getBoundingClientRect().left
// set size and border-width
cover.style.left = offsetLeft + 'px';
cover.style.top = offsetTop + 'px';
cover.style.width = targetWidth + 'px';
cover.style.height = targetHeight + 'px';
cover.style.borderWidth =
0 + 'px ' +
(pageWidth - targetWidth) + 'px ' +
(pageHeight - targetHeight) + 'px ' +
0 + 'px';
cover.style.display = 'block';
};
var elCover = document.getElementById('cover');
var arrElTarget = [
document.getElementById('container'),
document.getElementById('video'),
document.getElementById('menutext')
], index = 0;
coverGuide(elCover, arrElTarget[index]);
elCover.onclick = function() {
index++;
if (!arrElTarget[index]) {
index = 0;
}
coverGuide(elCover, arrElTarget[index]);
};