Vux: popup弹出时会自动scroll(0,0)

Created on 30 Aug 2017  ·  11Comments  ·  Source: airyland/vux


[email protected], [email protected], [email protected], [email protected]
调出popup时,会自动scroll(0,0)
之前用[email protected]并没有出现这种情况,于是对比调试发现,在popup的index.vue里发现一行代码导致这个问题的出现,
watch:show,代码line129
dom.addClass(document.body, 'modal-open')

componenpopup

Most helpful comment

@Zenfeder 确认你是 100% 布局再这样设置。

All 11 comments

研究发现,dom.js一个代码写错了。大佬好粗心啊
addClass (el, token) { if (el.classList) { el.classList.add(token) } else if (!this.hasClass(el, token)) { el.classNae += '' + token } },
el.className写成了classNae,赶紧更新版本吧
但是实际在执行el.classList.add(token)的时候,就已经srcoll0了,并不是报错影响的

你是指 window scroll(0, 0) 还是 popup 里的容器滚动到顶部。上代码吧。

是window.scroll(0,0)了,其实我测试了几次,是popup组件dom.addClass(document.body, 'modal-open'),在dom.js执行el.classList.add(token),添加的modal-open这个样式,引起的,我试过添加其他样式,并不影响,可能是样式的position:fixed引起的。
没有具体的代码,代码都是按照你的demo写的,没有太多改动,调用DateTime时并不会出现,因为DateTime,不是用popup。

demo 重现不了你所说的问题,还是给个可重现的吧。

暂时没有比较好的解决方案,容我三思 - -

demo采用的是100%布局,所以没有这个问题

可以的话先加上个全局样式,就能避免了

html, body {
  height: 100%;
  width: 100%;
  overflow-x: hidden;
}

下个版本不再自动这样处理,引入插件,变成可配置。仅在 $layout 为 VIEW_BOX 时才执行这个逻辑。

import { ConfigPlugin } from 'vux'

Vue.use(ConfigPlugin, {
  $layout: 'VIEW_BOX' // global config for VUX, since v2.6.0
})

@wg5945

html, body {
  height: 100%;
}
popup  的.vux-modal-open overflow,fixed,就不会引起 置顶了。

但是会引起一个问题。

window.addEventListener("scroll",xxx)
window 无法监控 onscroll 事件,导致页面功能失效,sticky组件也会失效。

@airyland
popup 类的组件能否加个 弹框打开之前的方法,我可以手动把html,body的height设为100%,关闭的时候,我再把他还原,这样可能就不会影响window 的 onscroll。

我目前采用 document.addEventListener("touchmove",xxx)去暂时代替一下。
或者是

.no-overflow {
    position: relative!important;
    overflow: auto!important;
}

给vux-modal-open no-overflow 设置一下。

目前还没遇到啥问题。。。

@airyland vux 版本2.3.4
我用了
Vue.use(ConfigPlugin, {
$layout: 'VIEW_BOX' // global config for VUX, since v2.6.0
})
结果x-dialog组件会跟着页面滚动,见下图:
image

@Zenfeder 确认你是 100% 布局再这样设置。

@airyland oh,这操作可以,感谢大佬。but:
@zhump 说的,这样会导致window.addEventListener("scroll",xxx)失效额,我页面有上拉加载更多的操作

@Zenfeder 改成监听 100% 布局的 div,如果你用 view-box 组件,监听 #vux_view_box_body

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hezhiwen940420 picture hezhiwen940420  ·  4Comments

LS1231 picture LS1231  ·  3Comments

varHarrie picture varHarrie  ·  4Comments

RenShine picture RenShine  ·  4Comments

iqiuye picture iqiuye  ·  4Comments