-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IMG图片尺寸自适配 #182
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题描述
所以希望找出一个能在不同屏幕显示不同大小图片的方法
本文实例都用vue来描述
优化方案
方案一:
通过函数来计算每个img的宽度
此种方式需要事先知道所有img的宽度
方案二:
将初始链接置于data-src里,在页面渲染完成后获取所有img标签,随后获取img的宽度,根据dpr计算得到最终的图片宽度,并将它置于src里
遇到的问题:
无法得知页面何时渲染完成,img标签也可能使用v-if来修饰,一开始是不存在的
如果在有属性变化时去遍历这个操作,当img的src为空时进行计算并赋值,可能会有性能问题(不确定)
具体方式如下:
此种方式只需要我们为图片设置data-src,不需要知道img具体的大小,但可能会有性能隐患
The text was updated successfully, but these errors were encountered: