-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Description
原理很简单,就是定义一个外框把页面包起来,把需要使用fixed
定位的元素设置成absolute
定位,然后设置外框元素的样式为overflow-y:scroll
即可,下面是实例:
假设外框元素为.wrap
,需要fixed
定位的元素为.position
:
DOM
<html>
<body>
<div class=".wrap">
<div class=".position"></div>
</div>
</body>
</html>
CSS
html, body, .wrap {
width: 100%;
height: 100%;
}
.wrap {
overflow-y: scroll;
-webkit-overflow-scrolling: touch; //因为使用overflow滚动体验不如正常的页面滚动,加上这个样式以后滚动即会变得顺滑
}
.position {
position: absolute;
}
Metadata
Metadata
Assignees
Labels
No labels