Home  >  Article  >  Web Front-end  >  html页面滚动时元素错位解决方案_html/css_WEB-ITnose

html页面滚动时元素错位解决方案_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:45:541562browse

  一个布局较复杂的页面,在手机浏览器上运行时,部分配置比较差的手机会出现滚动滚动条后,页面正常滚动,但部分元素却出现类似position:fixed一般悬浮在页面上,然后再滚动。看上去有点像视差滚动,但却一点都不好看。

解决方法:在滑动体上添加样式:transform:translateZ(0);-webkite-transform:translateZ(0)。

<div style="height:300px;overflow:auto">    <div style="transform:translateZ(0);-webkite-transform:translateZ(0);">          各种复杂的html      <div></div>

  加这个的目的是利用GPU加速(GPU缓存)。

  因为这个问题也发现,如果使用overflow:auto这样来滑动页面(html的滚动条形式),每次页面滑动时浏览器都会有频繁的scroll、update layer tree、composite layers。应是在最后一个环节上出了问题。这个问题的原因应该是在布局方式上。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn