Created
May 21, 2020 08:48
-
-
Save heycqing/28e8c81543b082db14cba7b59e604d34 to your computer and use it in GitHub Desktop.
判断是否支持检查webp格式
This file contains hidden or 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
| export const check_webp_support = () => { | |
| return new Promise( reslove => { | |
| let img = new Image(); | |
| img.onload = function () { | |
| let result = (img.width > 0) && (img.height > 0); | |
| reslove(result) | |
| }; | |
| img.onerror = function () { | |
| reslove(false) | |
| }; | |
| img.src = "data:image/webp;base64," + "UklGRhoAAABXRUJQVlA4TA0AAAAvAAAAEAcQERGIiP4HAA=="; | |
| }) | |
| } | |
| //原理: 生成一张src是webp格式的图片,通过判断图片大小是否存在 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment