css - 如何在 vue.js 3 和 quasar 中延迟加载 css 背景图像?
问题描述
当我在我的类星体应用程序中添加图像时,我使用q-img组件,它使用延迟加载来加载图像,当用户像这样滚动到它们时:
<q-img
src="https://placeimg.com/500/300/nature"
loading="lazy"
spinner-color="white"
height="140px"
style="max-width: 150px"
/>
这减少了初始页面加载时间,仅在用户需要查看图像时才加载图像,并允许我添加高质量图像而不必担心应用程序运行缓慢。
但是我不能在背景图像中执行此操作,因为我在 css 中添加背景图像,如下所示:
.landing-section {
height: 37rem;
background: url("/images/home/landing-section/landing-img.png");
background-repeat: no-repeat;
background-size: cover;
background-position: 20%;
display: flex;
align-items: center;
}
背景图像允许您将图像堆叠在一起并轻松地在它们之上添加内容,而无需使用诸如absolute
css 属性或grid
.
有没有办法在它们来查看(用户滚动到它们)时延迟加载背景图像?
如果没有,有没有办法在同一页面中延迟加载组件到视口?
解决方案
推荐阅读
- qt - 无法设置 LineSeries 的透明度{}
- ruby-on-rails - Rails 6多态模型给出验证错误
- javascript - 滚动时触发 Lottie 动画
- powershell - 使用 Powershell 将多行对象转换为多个对象
- c++ - 使用带有右值的条件运算符时,采用 const pmr::vector<>& 不传播分配器
- javascript - How do I get BOT to create a private chat? (Discord.js)
- javascript - 推荐部分在我的网站上不起作用
- javascript - 将最后一个参数传递给函数 - JavaScript
- next.js - 在 Axios 拦截器下捕获 400 和 500 用于哨兵
- puppeteer - Crawlera & Puppeteer - HTTPS 中的身份验证问题