Created
June 3, 2020 08:18
-
-
Save imbyc/f5f603dd8480dd36ad5ae0f91324237d to your computer and use it in GitHub Desktop.
[js 判断是否是刘海屏]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 判断刘海屏 | |
function hasNotch() { | |
var proceed = false | |
var div = document.createElement('div') | |
if (CSS.supports('padding-bottom: env(safe-area-inset-bottom)')) { | |
div.style.paddingBottom = 'env(safe-area-inset-bottom)' | |
proceed = true | |
} else if (CSS.supports('padding-bottom: constant(safe-area-inset-bottom)')) { | |
div.style.paddingBottom = 'constant(safe-area-inset-bottom)' | |
proceed = true | |
} | |
if (proceed) { | |
document.body.appendChild(div) | |
var calculatedPadding = parseInt(window.getComputedStyle(div).paddingBottom) | |
document.body.removeChild(div) | |
if (calculatedPadding > 0) { | |
return true | |
} | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment