progressive-image.js:让图片加载更智能,更快捷!

progressive-image.js:让图片加载更智能,更快捷!

progressive-image.jsA lazy-loading progressive image similar to those seen on Facebook and Medium.项目地址:https://gitcode.com/gh_mirrors/pr/progressive-image.js

在线演示 | GitHub仓库 | npm包 | 捐赠 | @craigbuckler | 个人网站

progressive-image.js 是一个轻量级的JavaScript库,它实现了类似于Facebook和Medium上的渐进式加载图像效果。库会先显示一幅模糊的小图,当元素进入视口时再替换为全分辨率的图像,有效节省了不必要的带宽,并提高了加载速度。

项目技术分析

该库的工作原理是,在页面加载时仅加载小尺寸的预览图,然后通过监听滚动事件,当大图所在的部分进入可视区域时,以原图替换预览图。支持任何图像类型,同时也兼容响应式图像(srcsetsizes 属性)以及CSS背景图片。它的亮点在于,它无需任何外部依赖,可以与任何框架无缝集成。

应用场景

无论是在博客、新闻网站还是电商平台上,progressive-image.js 都能发挥其优势。在长篇文章中,只有当读者滚动到特定位置时,图像才会加载,这大大加快了页面的初始加载速度,提供了更好的用户体验,特别是在移动设备上。

项目特点

  1. 节省带宽:仅在需要时才加载高分辨率图像。
  2. 高性能:只在图片进入视口时加载,提升了整体性能。
  3. 跨浏览器兼容:支持IE10及以上版本和其他现代浏览器。
  4. 渐进增强:即使在不支持脚本的老式浏览器中也能正常工作。
  5. 轻量级:压缩后的JavaScript代码仅为1,407字节,可选CSS为407字节。
  6. 无依赖:可直接用于任何开发环境。
  7. 自定义效果:允许应用任何CSS揭示效果。
  8. 强大的错误处理:在下载失败后最多尝试三次。

使用方法

简单地将CSS和JavaScript文件引入你的HTML:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/progressive-image.js/dist/progressive-image.css">
<script src="https://cdn.jsdelivr.net/npm/progressive-image.js/dist/progressive-image.js" async></script>

或通过npm安装并使用打包工具。

接着,只需在HTML中添加渐进式加载的图片:

<a href="full.jpg" class="progressive replace">
  <img src="tiny.jpg" class="preview" alt="image" />
</a>

现在,你可以享受progressive-image.js带来的高效、智能的图片加载体验。想要了解更多详细信息和示例,请访问在线演示

让我们一起,让网页加载变得更快,体验更好!

progressive-image.jsA lazy-loading progressive image similar to those seen on Facebook and Medium.项目地址:https://gitcode.com/gh_mirrors/pr/progressive-image.js

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
<div class="scene-inner" style="--backgroundImage1920:url(https\:\/\/p\.ampmake\.com\/lilibrary\/20220916\/sync20220916\/28fd1387-0e31-48a7-9877-951b8f99a53b\.jpg\@d_progressive); --backgroundImage1024:url(https\:\/\/p\.ampmake\.com\/lilibrary\/892163417397753\/7b4fcb9c-7a9b-477d-abc2-9f7d667536ee\.jpg\@d_progressive); --backgroundImage768:url(https\:\/\/p\.ampmake\.com\/lilibrary\/892162356787600\/46a2e7fd-9735-4bb0-9926-3e861073b2c5\.jpg\@d_progressive); --backgroundImage720:url(https\:\/\/p\.ampmake\.com\/lilibrary\/20220916\/sync20220916\/99f01e42-a3d6-49bf-960b-431e90f222bc\.jpg\@d_progressive);"><div class="product-fadebox top-default active"><div class="product-fadebox-item"><div class="product-model">理想L9 </div></div><div class="product-fadebox-item"><div class="product-title">家庭智能旗舰SUV</div></div><div class="product-fadebox-item"><div class="product-model-image" style="--logo:url(https\:\/\/p\.ampmake\.com\/lilibrary\/650629529518819\/e16dc66a-65c2-4eda-90d0-23721d32d738\.png);"></div></div><div class="product-fadebox-item"><div class="product-buttonlist"><div class="product-button sub firstscreen-button-vr">VR看车</div><div class="product-button main firstscreen-button-buy">预约试驾</div><div class="product-button main firstscreen-button-buy">立即定购</div></div></div><div class="product-fadebox-item"><div class="product-buttonlist"></div></div></div><div class="scene-arrow"><i class="iconfont iconfont-arrowdown"></i></div></div> 是什么意思
07-08
这是一段 HTML 代码,描述了一个包含多个子元素的 `<div>` 元素。让我为您解析每个子元素的含义: 1. `<div class="scene-inner" style="--backgroundImage1920:url(https\:\/\/p\.ampmake\.com\/lilibrary\/20220916\/sync20220916\/28fd1387-0e31-48a7-9877-951b8f99a53b\.jpg\@d_progressive); --backgroundImage1024:url(https\:\/\/p\.ampmake\.com\/lilibrary\/892163417397753\/7b4fcb9c-7a9b-477d-abc2-9f7d667536ee\.jpg\@d_progressive); --backgroundImage768:url(https\:\/\/p\.ampmake\.com\/lilibrary\/892162356787600\/46a2e7fd-9735-4bb0-9926-3e861073b2c5\.jpg\@d_progressive); --backgroundImage720:url(https\:\/\/p\.ampmake\.com\/lilibrary\/20220916\/sync20220916\/99f01e42-a3d6-49bf-960b-431e90f222bc\.jpg\@d_progressive);">`: - `class="scene-inner"`:指定该 `<div>` 元素的 CSS 类名为 "scene-inner",可用于在 CSS 中对其进行样式设置。 - `style="--backgroundImage1920:url(https\:\/\/p\.ampmake\.com\/lilibrary\/20220916\/sync20220916\/28fd1387-0e31-48a7-9877-951b8f99a53b\.jpg\@d_progressive); --backgroundImage1024:url(https\:\/\/p\.ampmake\.com\/lilibrary\/892163417397753\/7b4fcb9c-7a9b-477d-abc2-9f7d667536ee\.jpg\@d_progressive); --backgroundImage768:url(https\:\/\/p\.ampmake\.com\/lilibrary\/892162356787600\/46a2e7fd-9735-4bb0-9926-3e861073b2c5\.jpg\@d_progressive); --backgroundImage720:url(https\:\/\/p\.ampmake\.com\/lilibrary\/20220916\/sync20220916\/99f01e42-a3d6-49bf-960b-431e90f222bc\.jpg\@d_progressive);"`:指定该元素的内联样式,其中包含了四个背景图片的 URL,每个 URL 针对不同的屏幕宽度。 2. `<div class="product-fadebox top-default active">`:指定一个具有多个 CSS 类名的 `<div>` 元素,用于设置产品信息的淡入淡出效果和默认样式。 3. `<div class="product-fadebox-item">`:指定一个包含产品信息的子元素 `<div>` 元素。 4. `<div class="product-model">理想L9 </div>`:指定一个 CSS 类名为 "product-model" 的 `<div>` 元素,用于显示产品型号 "理想L9"。 5. `<div class="product-title">家庭智能旗舰SUV</div>`:指定一个 CSS 类名为 "product-title" 的 `<div>` 元素,用于显示产品标题 "家庭智能旗舰SUV"。 6. `<div class="product-model-image" style="--logo:url(https\:\/\/p\.ampmake\.com\/lilibrary\/650629529518819\/e16dc66a-65c2-4eda-90d0-23721d32d738\.png);"></div>`:指定一个 CSS 类名为 "product-model-image" 的 `<div>` 元素,用于显示产品型号的图像,其中内联样式设置了背景图像的 URL。 7. `<div class="product-button sub firstscreen-button-vr">VR看车</div>`:指定一个包含多个 CSS 类名的 `<div>` 元素,用于显示一个按钮,按钮文本为 "VR看车"。 8. `<div class="product-button main firstscreen-button-buy">预约试驾</div>`:指定一个包含多个 CSS 类名的 `<div>` 元素,用于显示一个按钮,按钮文本为 "预约试驾"。 9. `<div class="product-button main firstscreen-button-buy">立即定购</div>`:指定一个包含多个 CSS 类名的 `<div>` 元素,用于显示一个按钮,按钮文本为 "立即定购"。 10. `<div class="scene-arrow"><i class="iconfont iconfont-arrowdown"></i></div>`:指定一个包含子元素的 `<div>` 元素,其中包含了一个 `<i>` 元素,用于显示一个箭头图标。 这段代码描述了一个场景(scene),其中包含了产品信息和按钮等元素。具体的样式和行为可能需要结合 CSS 和 JavaScript 进行进一步的分析。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

伍辰惟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值