omi-mp - record the location of scroll bars
This commit is contained in:
parent
38d28480b7
commit
82dd8cac52
|
@ -189,25 +189,25 @@ gulp.task('route', ['copy'], (cb) => {
|
|||
let json = require('./src/mp/app.json')
|
||||
//fs.unlinkSync('./src/index.js')
|
||||
|
||||
fs.writeFile('./src/index.js', `import { render } from 'omi'
|
||||
import 'omi-router'
|
||||
import './utils/mp'
|
||||
fs.writeFile('./src/index.js', `import 'omi-router'
|
||||
import { routeUpdate } from './utils/mp'
|
||||
import './mp/app'
|
||||
|
||||
const root = document.querySelector('#root')
|
||||
|
||||
route('*', evt => {
|
||||
title('index')
|
||||
empty('#root')
|
||||
render(<we-index />, '#root')
|
||||
routeUpdate(<we-index />, 'we-index', evt.byNative, root)
|
||||
})
|
||||
|
||||
${route(json.pages)}
|
||||
function empty(selector) {
|
||||
const node = document.querySelector(selector)
|
||||
while (node.firstChild) {
|
||||
node.removeChild(node.firstChild)
|
||||
}
|
||||
document.documentElement.scrollTop = 0
|
||||
document.body.scrollTop = 0
|
||||
|
||||
window.onscroll = function(){
|
||||
root.childNodes.forEach(child => {
|
||||
if(child.style.display !== 'none'){
|
||||
child._preScrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function title(value) {
|
||||
|
@ -223,8 +223,7 @@ function route(arr) {
|
|||
const name = item.split('/')[1]
|
||||
result.push(`route('${item.replace('pages', '..')}', evt => {
|
||||
title('${name}')
|
||||
empty('#root')
|
||||
render(<we-${name} />, '#root')
|
||||
routeUpdate(<we-${name} />, 'we-${name}', evt.byNative, root)
|
||||
})
|
||||
`)
|
||||
})
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
"jest": "20.0.4",
|
||||
"object-assign": "4.1.1",
|
||||
"omi": "latest",
|
||||
"omi-router": "^2.0.5",
|
||||
"omi-router": "latest",
|
||||
"postcss-flexbugs-fixes": "3.2.0",
|
||||
"postcss-loader": "2.0.8",
|
||||
"prettier": "^1.14.3",
|
||||
|
|
|
@ -19,6 +19,16 @@ route('../logs/logs', evt => {
|
|||
routeUpdate(<we-logs />, 'we-logs', evt.byNative, root)
|
||||
})
|
||||
|
||||
|
||||
window.onscroll = function(){
|
||||
root.childNodes.forEach(child => {
|
||||
if(child.style.display !== 'none'){
|
||||
child._preScrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function title(value) {
|
||||
document.title = value
|
||||
}
|
||||
|
|
@ -22,7 +22,10 @@ const mpOption = Page({
|
|||
//事件处理函数
|
||||
bindViewTap: function() {
|
||||
wx.navigateTo({
|
||||
url: '../logs/logs?name=dntzhang&age=18'
|
||||
url: '../logs/logs?name=dntzhang&age=18',
|
||||
// alive: true, //当前视图是否alive,默认ture
|
||||
// scollTop: 0 //目标url的scollTop,不传scollTop的话使用以前保留的
|
||||
// 浏览器后退行为刚好 alive用true,scollTop不传
|
||||
})
|
||||
},
|
||||
onLoad: function () {
|
||||
|
@ -103,3 +106,4 @@ function render() {
|
|||
}
|
||||
|
||||
customElements.define('we-index', Element)
|
||||
|
|
@ -75,9 +75,6 @@ function getUrlParams(url) {
|
|||
|
||||
export function routeUpdate(node, selector, byNative, root) {
|
||||
root.childNodes.forEach(child => {
|
||||
if(child.style.display !== 'none'){
|
||||
child._preScrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
|
||||
}
|
||||
child.style.display = 'none'
|
||||
})
|
||||
if (byNative) {
|
||||
|
|
Loading…
Reference in New Issue