forked from shama/letswritecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (37 loc) · 1001 Bytes
/
index.js
File metadata and controls
40 lines (37 loc) · 1001 Bytes
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
require('./bears.js')
require('./sizer.js')
const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.attributeName === 'style') {
centerModal()
}
if (mutation.addedNodes.length) {
console.log('Added', mutation.addedNodes[0])
}
if (mutation.removedNodes.length) {
console.log('Removed', mutation.removedNodes[0])
}
})
})
const bears = document.querySelector('ul.bears')
observer.observe(bears, {
childList: false,
attributes: true
})
function centerModal () {
const width = parseInt(bears.offsetWidth, 10)
const height = parseInt(bears.offsetHeight, 10)
Object.assign(bears.style, {
top: '50%',
left: '50%',
marginTop: -(height / 2) + 'px',
marginLeft: -(width / 2) + 'px',
})
}
// const poller = setInterval(function () {
// const bear = document.querySelector('ul.bears li')
// if (bear) {
// console.log(bear)
// clearInterval(poller)
// }
// }, 1000)