forked from didi/mand-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.js
More file actions
56 lines (50 loc) · 1.76 KB
/
render.js
File metadata and controls
56 lines (50 loc) · 1.76 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
import {root, inBrowser} from './env'
/* istanbul ignore file */
export const render = (function(global) {
// for ssr
if (!inBrowser) {
return function(content, left, top) {
content.style.marginLeft = left ? `${-left}px` : ''
content.style.marginTop = top ? `${-top}px` : ''
}
}
const docStyle = document.documentElement.style
let engine
if (global.opera && Object.prototype.toString.call(opera) === '[object Opera]') {
engine = 'presto'
} else if ('MozAppearance' in docStyle) {
engine = 'gecko'
} else if ('WebkitAppearance' in docStyle) {
engine = 'webkit'
} else if (typeof navigator.cpuClass === 'string') {
engine = 'trident'
}
const vendorPrefix = {
trident: 'ms',
gecko: 'Moz',
webkit: 'Webkit',
presto: 'O',
}[engine]
const helperElem = document.createElement('div')
const perspectiveProperty = vendorPrefix + 'Perspective'
const transformProperty = vendorPrefix + 'Transform'
if (helperElem.style[perspectiveProperty] !== undefined) {
return function(content, left, top, zoom = 1, useNativeDriver = true) {
if (useNativeDriver) {
content.style[transformProperty] = `translate3d(${-left}px,${-top}px,0) scale(${zoom})`
} else {
content.style[transformProperty] = `translate(${-left}px,${-top}px) scale(${zoom})`
}
}
} else if (helperElem.style[transformProperty] !== undefined) {
return function(content, left, top, zoom = 1) {
content.style[transformProperty] = `translate(${-left}px,${-top}px) scale(${zoom})`
}
} else {
return function(content, left, top, zoom) {
content.style.marginLeft = left ? `${-left}px` : ''
content.style.marginTop = top ? `${-top}px` : ''
content.style.zoom = zoom || ''
}
}
})(root)