Skip to content

Instantly share code, notes, and snippets.

Avatar
❤️
coding with heart

Jacob jacob-lcs

❤️
coding with heart
View GitHub Profile
@jacob-lcs
jacob-lcs / localstorage.js
Last active Jan 2, 2021
对 localstorage 进行封装,使用方法见 comment
View localstorage.js
let storage = window.localStorage;
/**
* 判断是否为 JSON 对象
* @param obj
* @returns {boolean}
*/
function isJSON(obj) {
obj = JSON.stringify(obj);
return /^\{[\s\S]*\}$/.test(obj);
@jacob-lcs
jacob-lcs / supportWebP.js
Last active Jan 30, 2021
判断当前宿主环境是否支持 webp
View supportWebP.js
// 方法一,非异步方式
const supportWebP = (function () {
var canvas = typeof document === 'object' ? document.createElement('canvas') : {}
canvas.width = canvas.height = 1
return canvas.toDataURL ? canvas.toDataURL('image/webp').indexOf('image/webp') === 5 : false
})()
// 异步方式获取,比较适合系统中存在一个系统变量来保存结果
window.isSupportWebp = false; // 是否支持
(function() {