forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdom.js
More file actions
62 lines (51 loc) · 1.14 KB
/
dom.js
File metadata and controls
62 lines (51 loc) · 1.14 KB
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
export function offset (el) {
if (el === window) {
return {top: 0, left: 0}
}
let {top, left} = el.getBoundingClientRect()
return {top, left}
}
export function style (el, property) {
return window.getComputedStyle(el).getPropertyValue(property)
}
export function height (el) {
if (el === window) {
return window.innerHeight
}
return parseFloat(style(el, 'height'))
}
export function width (el) {
if (el === window) {
return window.innerWidth
}
return parseFloat(style(el, 'width'))
}
export function css (element, css) {
let style = element.style
Object.keys(css).forEach(prop => {
style[prop] = css[prop]
})
}
export function viewport () {
return {
width: window.innerWidth,
height: window.innerHeight
}
}
export function ready (fn) {
if (typeof fn !== 'function') {
return
}
if (document.readyState === 'complete') {
return fn()
}
document.addEventListener('DOMContentLoaded', fn, false)
}
const prefix = ['-webkit-', '-moz-', '-ms-', '-o-']
export function cssTransform (val) {
let o = {transform: val}
prefix.forEach(p => {
o[p + 'transform'] = val
})
return o
}