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 | function switchPage (oldUrlParam, newUrlParam) {
|
22 | var oldPage = oldUrlParam
|
23 | var newPage = newUrlParam
|
24 | let newPagParamList = newPage.split('&')
|
25 | if (newPage) newPage = newPagParamList[0]
|
26 |
|
27 |
|
28 |
|
29 | if (oldPage === undefined) {
|
30 | oldPage = globalConfig.entry
|
31 | } else {
|
32 | oldPage = oldPage.split('&')[0]
|
33 | }
|
34 | var oldDom = document.getElementById('ox-' + oldPage)
|
35 | var newDom = document.getElementById('ox-' + newPage)
|
36 | if (!newDom) {
|
37 | console.error('页面不存在!')
|
38 | return
|
39 | }
|
40 |
|
41 | if (newPagParamList.length > 1) {
|
42 | var animationIn = getQueryString(newUrlParam, 'in')
|
43 | var animationOut = getQueryString(newUrlParam, 'out')
|
44 |
|
45 | if (!animationIn || !animationOut) {
|
46 | dispalyEffect(oldDom, newDom)
|
47 | return
|
48 | }
|
49 | oldDom.style.position = 'absolute'
|
50 |
|
51 | newDom.style.display = 'block'
|
52 | newDom.style.position = 'absolute'
|
53 |
|
54 | animationIn.split(',').forEach(value => {
|
55 | oldDom.classList.add('ox-page-' + value)
|
56 | })
|
57 | animationOut.split(',').forEach(value => {
|
58 | newDom.classList.add('ox-page-' + value)
|
59 | })
|
60 | oldDom.addEventListener("animationend", function() {
|
61 |
|
62 | oldDom.style.display = 'none'
|
63 | oldDom.style.position = ''
|
64 |
|
65 | animationIn.split(',').forEach(value => {
|
66 | oldDom.classList.remove('ox-page-' + value)
|
67 | })
|
68 | })
|
69 | newDom.addEventListener("animationend", function() {
|
70 |
|
71 | newDom.style.position = ''
|
72 | animationOut.split(',').forEach(value => {
|
73 | newDom.classList.remove('ox-page-' + value)
|
74 | })
|
75 | })
|
76 | } else {
|
77 | dispalyEffect(oldDom, newDom)
|
78 | }
|
79 |
|
80 | window.ozzx.activePage = newPage
|
81 | runPageFunction(newPage, newDom)
|
82 | } |
\ | No newline at end of file |