position:sticky 定位 position:fixed
2016-01-28 14:45
281 查看
它的表现类似position:relative和position:fixed的合体,当目标区域在屏幕中可见时,它的行为就像position:relative; 而当页面滚动超出目标区域时,它的表现就像position:fixed,它会固定在目标位置。
.sticky {
position: -webkit-sticky;
position:sticky;
top: 15px;
}
不支持的fall back:
<div class="header"></div>
.sticky {
position: fixed;
top: 0;
}
.header {
width: 100%;
background: #F6D565;
padding: 25px 0;
}
var header = document.querySelector('.header');
var origOffsetY = header.offsetTop;
function onScroll(e) {
window.scrollY >= origOffsetY ? header.classList.add('sticky') :
header.classList.remove('sticky');
}
document.addEventListener('scroll', onScroll);
http://www.qianduan.net/position-sticky-introduction.html
position:fixed
Android 2.2+ 需要添加下面的meta才正常:
<meta name="viewport" content="width=device-width, user-scalable=no">
在旧的IOS Safari 上也有问题
1、页面滚动的时候fixed元素颤抖
2、旋转屏幕的时候飘走了
3、fixed元素里有focusable的元素(例如input),会让这个fixed元素移位
https://remysharp.com/2012/05/24/issues-with-position-fixed-scrolling-on-ios
.sticky {
position: -webkit-sticky;
position:sticky;
top: 15px;
}
不支持的fall back:
<div class="header"></div>
.sticky {
position: fixed;
top: 0;
}
.header {
width: 100%;
background: #F6D565;
padding: 25px 0;
}
var header = document.querySelector('.header');
var origOffsetY = header.offsetTop;
function onScroll(e) {
window.scrollY >= origOffsetY ? header.classList.add('sticky') :
header.classList.remove('sticky');
}
document.addEventListener('scroll', onScroll);
http://www.qianduan.net/position-sticky-introduction.html
position:fixed
Android 2.2+ 需要添加下面的meta才正常:
<meta name="viewport" content="width=device-width, user-scalable=no">
在旧的IOS Safari 上也有问题
1、页面滚动的时候fixed元素颤抖
2、旋转屏幕的时候飘走了
3、fixed元素里有focusable的元素(例如input),会让这个fixed元素移位
https://remysharp.com/2012/05/24/issues-with-position-fixed-scrolling-on-ios
相关文章推荐
- 个性签名
- c#版在pc端发起微信扫码支付
- View绘制流程简述
- HDU 1286 找新朋友 (欧拉函数_打表)
- 循环生成学号/
- EventBus详细解析
- IDA动态调试Android的DEX文件
- js对象或json对象深拷贝
- 通用的contain函数
- webpack 发布配置
- 使用nodejs,express,mysql,Bootstrap开发采购招标网站(三)Bootstrap-table实现Ajax删除数据
- js对象转json字符串,并保留js对象中的javascript脚本
- 测试必备技能系列1 :通过mysql命令进行脚本数据导入
- Linux命令—echo
- SQL Server Cast and Convert
- EL表达式 (详解)
- iOS之设置头像(访问系统相册、本地上传)
- ubuntu命令收集
- Visual formatting model 可视化格式模型
- overflow:hidden