New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
移动Web开发,4行代码检测浏览器是否支持position:fixed #7
Comments
这个方法确实比较周全,教科书般的特性检测。 我自己的项目里是直接用黑名单,简单粗暴搞定了,哈哈: |
请教下为啥检测的div一定要设置z-index |
@sixwinds 具体我也忘记了,时间太久。好像是如果不写z-index,浏览器在计算样式时,会将fixed计算成static |
@maxzhang google了下没有找到fixed会被计算成static,只发现了这个类似fixed不work的问题: http://stackoverflow.com/questions/19254146/position-fixed-not-working-in-mobile-browser |
貌似现在所有浏览器都支持fixed定位(包括用你的方法显示也都是支持) 但是国内许多浏览器对fixed的支持表现 真的是杂乱无章啊 有点仅仅是显示fixed 但是真正用的时候 却是一塌糊涂。 这才是最无奈的地方。我们更多的时候只能用户特性来检测。表现在页面上的行为很难控制的。 |
http://bradfrostweb.com/blog/mobile/fixed-position/ 贴一个总结position:fixed的文章。 |
非常感谢分享技术 必须32个赞 |
点赞~ |
近期项目的开发遇到类似的问题,很实用的代码 |
为什么要不div append到body?不append的话,直接判断div.style.position会有什么问题吗? |
@oddjohn 不添加该方法返回""; |
m |
重定向:http://www.maxzhang.com/2013/07/%E7%A7%BB%E5%8A%A8%E7%AB%AFweb%E9%A1%B5%E9%9D%A2%E4%BD%BF%E7%94%A8position-fixed%E9%97%AE%E9%A2%98%E6%80%BB%E7%BB%93/
不废话,直接上代码
对于不支持fixed的浏览器,
window.getComputedStyle(div).position
计算出来的值会是absolute
。在这段代码的基础上,可以封装一个公共函数,并将已知的不支持fixed浏览器直接过滤掉。
The text was updated successfully, but these errors were encountered: