{"action":"created","issue":{"url":"https://api.github.com/repos/maxzhang/maxzhang.github.com/issues/7","repository_url":"https://api.github.com/repos/maxzhang/maxzhang.github.com","labels_url":"https://api.github.com/repos/maxzhang/maxzhang.github.com/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/maxzhang/maxzhang.github.com/issues/7/comments","events_url":"https://api.github.com/repos/maxzhang/maxzhang.github.com/issues/7/events","html_url":"https://github.com/maxzhang/maxzhang.github.com/issues/7","id":20020570,"number":7,"title":"移动Web开发，4行代码检测浏览器是否支持position:fixed","user":{"login":"maxzhang","id":1566939,"avatar_url":"https://avatars.githubusercontent.com/u/1566939?v=3","gravatar_id":"","url":"https://api.github.com/users/maxzhang","html_url":"https://github.com/maxzhang","followers_url":"https://api.github.com/users/maxzhang/followers","following_url":"https://api.github.com/users/maxzhang/following{/other_user}","gists_url":"https://api.github.com/users/maxzhang/gists{/gist_id}","starred_url":"https://api.github.com/users/maxzhang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maxzhang/subscriptions","organizations_url":"https://api.github.com/users/maxzhang/orgs","repos_url":"https://api.github.com/users/maxzhang/repos","events_url":"https://api.github.com/users/maxzhang/events{/privacy}","received_events_url":"https://api.github.com/users/maxzhang/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/maxzhang/maxzhang.github.com/labels/%E7%A7%BB%E5%8A%A8Web%E5%BC%80%E5%8F%91","name":"移动Web开发","color":"207de5"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2013-09-25T03:37:36Z","updated_at":"2016-09-13T12:14:36Z","closed_at":"2015-06-18T03:26:10Z","body":"重定向：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/\r\n\r\n---------------------\r\n\r\n不废话，直接上代码\r\n\r\n```\r\nvar div = document.createElement('div');\r\ndiv.style.cssText = 'display:none;position:fixed;z-index:100;';\r\nbody.appendChild(div);\r\nconsole.log(window.getComputedStyle(div).position != 'fixed');\r\n```\r\n\r\n对于不支持fixed的浏览器，```window.getComputedStyle(div).position```计算出来的值会是```absolute```。\r\n\r\n在这段代码的基础上，可以封装一个公共函数，并将已知的不支持fixed浏览器直接过滤掉。\r\n\r\n```\r\nfunction isSupportFixed() {\r\n    var userAgent = window.navigator.userAgent, \r\n        ios = userAgent.match(/(iPad|iPhone|iPod)\\s+OS\\s([\\d_\\.]+)/),\r\n        ios5below = ios && ios[2] && (parseInt(ios[2].replace(/_/g, '.'), 10) < 5),\r\n        operaMini = /Opera Mini/i.test(userAgent),\r\n        body = document.body,\r\n        div, isFixed;\r\n\r\n    div = document.createElement('div');\r\n    div.style.cssText = 'display:none;position:fixed;z-index:100;';\r\n    body.appendChild(div);\r\n    isFixed = window.getComputedStyle(div).position != 'fixed';\r\n    body.removeChild(div);\r\n    div = null;\r\n\r\n    return !!(isFixed || ios5below || operaMini);\r\n}\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/maxzhang/maxzhang.github.com/issues/comments/246662441","html_url":"https://github.com/maxzhang/maxzhang.github.com/issues/7#issuecomment-246662441","issue_url":"https://api.github.com/repos/maxzhang/maxzhang.github.com/issues/7","id":246662441,"user":{"login":"Mmzer","id":9158841,"avatar_url":"https://avatars.githubusercontent.com/u/9158841?v=3","gravatar_id":"","url":"https://api.github.com/users/Mmzer","html_url":"https://github.com/Mmzer","followers_url":"https://api.github.com/users/Mmzer/followers","following_url":"https://api.github.com/users/Mmzer/following{/other_user}","gists_url":"https://api.github.com/users/Mmzer/gists{/gist_id}","starred_url":"https://api.github.com/users/Mmzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mmzer/subscriptions","organizations_url":"https://api.github.com/users/Mmzer/orgs","repos_url":"https://api.github.com/users/Mmzer/repos","events_url":"https://api.github.com/users/Mmzer/events{/privacy}","received_events_url":"https://api.github.com/users/Mmzer/received_events","type":"User","site_admin":false},"created_at":"2016-09-13T12:14:36Z","updated_at":"2016-09-13T12:14:36Z","body":"m"}}
{"actor":{"display_login":"Mmzer"}}