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
71 lines (58 loc) · 1.27 KB
/
dom.js
File metadata and controls
71 lines (58 loc) · 1.27 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
63
64
65
66
67
68
69
70
71
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 viewport().height
}
return parseFloat(style(el, 'height'))
}
export function width (el) {
if (el === window) {
return viewport().width
}
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 () {
let
e = window,
a = 'inner'
if (!('innerWidth' in window)) {
a = 'client'
e = document.documentElement || document.body
}
return {
width: e[a + 'Width'],
height: e[a + 'Height']
}
}
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
}