JavaScript 问题收集

# element.getBoundingClientRect的兼容性问题

const rect = element.getBoundingClientRect();

方法getBoundingClientRect获取元素相对于视口的位置,返回对象rect,在大部分手机中,rect包含下面的对象:

image from dependency

但是在低版本的荣耀手机中,rect只包含了下面图中几个对象,比其他手机机型少了xy属性。

image from dependency

# IOS不支持webp格式的图片

解决:自动引入目录中的文件

function importAll(r) {
  r.keys().forEach(r);
}
importAll(require.context('../assets/sprites', true, /\.svg$/));