1 |
|
2 |
|
3 |
|
4 | function getQueryString(newUrlParam, name) {
|
5 | var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i")
|
6 | var r = newUrlParam.match(reg)
|
7 | if (r != null) return unescape(r[2])
|
8 | return null;
|
9 | }
|
10 |
|
11 |
|
12 | function dispalyEffect (oldDom, newDom) {
|
13 | if (oldDom) {
|
14 |
|
15 | oldDom.style.display = 'none'
|
16 | }
|
17 |
|
18 | newDom.style.display = 'block'
|
19 | }
|
20 |
|
21 |
|
22 | function animation (oldDom, newDom, animationIn, animationOut) {
|
23 | oldDom.addEventListener("animationend", oldDomFun)
|
24 | newDom.addEventListener("animationend", newDomFun)
|
25 |
|
26 | oldDom.style.position = 'absolute'
|
27 |
|
28 | newDom.style.display = 'block'
|
29 | newDom.style.position = 'absolute'
|
30 |
|
31 | animationIn.split(',').forEach(value => {
|
32 | console.log('add:' + value)
|
33 | oldDom.classList.add('ox-page-' + value)
|
34 | })
|
35 | animationOut.split(',').forEach(value => {
|
36 | console.log('add:' + value)
|
37 | newDom.classList.add('ox-page-' + value)
|
38 | })
|
39 |
|
40 | function oldDomFun () {
|
41 |
|
42 | oldDom.style.display = 'none'
|
43 |
|
44 | oldDom.style.position = ''
|
45 |
|
46 | animationIn.split(',').forEach(value => {
|
47 | console.log('del:' + value)
|
48 | oldDom.classList.remove('ox-page-' + value)
|
49 | })
|
50 |
|
51 | oldDom.removeEventListener('animationend', oldDomFun, false)
|
52 | }
|
53 |
|
54 |
|
55 | function newDomFun () {
|
56 |
|
57 | newDom.style.position = ''
|
58 | animationOut.split(',').forEach(value => {
|
59 | console.log('del:' + value)
|
60 | newDom.classList.remove('ox-page-' + value)
|
61 | })
|
62 |
|
63 | newDom.removeEventListener('animationend', newDomFun, false)
|
64 | }
|
65 | }
|
66 |
|
67 |
|
68 |
|
69 | function switchPage (oldUrlParam, newUrlParam) {
|
70 | var oldPage = oldUrlParam
|
71 | var newPage = newUrlParam
|
72 | let newPagParamList = newPage.split('&')
|
73 | if (newPage) newPage = newPagParamList[0]
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | if (oldPage === undefined) {
|
79 | oldPage = globalConfig.entry
|
80 | } else {
|
81 | oldPage = oldPage.split('&')[0]
|
82 | }
|
83 | var oldDom = document.getElementById('ox-' + oldPage)
|
84 | var newDom = document.getElementById('ox-' + newPage)
|
85 |
|
86 | if (!newDom) {
|
87 | console.error('页面不存在!')
|
88 | return
|
89 | }
|
90 |
|
91 | if (newPagParamList.length > 1) {
|
92 | var animationIn = getQueryString(newUrlParam, 'in')
|
93 | var animationOut = getQueryString(newUrlParam, 'out')
|
94 |
|
95 |
|
96 | if (!animationIn || !animationOut) {
|
97 | dispalyEffect(oldDom, newDom)
|
98 | return
|
99 | }
|
100 | animation(oldDom, newDom, animationIn, animationOut)
|
101 |
|
102 |
|
103 | } else {
|
104 | dispalyEffect(oldDom, newDom)
|
105 | }
|
106 |
|
107 | window.ozzx.activePage = newPage
|
108 | runPageFunction(newPage, newDom)
|
109 | } |
\ | No newline at end of file |