1.0.4 • Published 5 years ago

@icedesign/img v1.0.4

Weekly downloads
72
License
MIT
Repository
github
Last release
5 years ago

title: Img category: Components

chinese: 图片组件

ICE 图片组件,用来增强图片显示效果。

安装和升级

npm i @icedesign/img -S

参数(props)

参数名说明必填类型默认值可选值备注
type图片显示模式falsestringcovercover、contain
src图片 urltruestring
shape形状展现falsestringsharpcircle、sharp、rounded
title图片的 title,hover 上去会显示出来falsestring''
alt图片的 alt 通常用于屏幕阅读器(盲人)识别falsestring''
className图片的 classNamefalsestring''
style图片的 inline stylefalseobject{}
width图片显示宽度falsenumber计算图片必需,不传则表现形式等同于普通 img 标签。
height图片显示高度falsenumber计算图片必需,不传则表现形式等同于普通 img 标签。
errorImgSrc图片加载失败的兜底图片falsestring如果图片加载失败,那么将用这张图来代替
onError图片加载失败的回调方法falsefunction如果图片加载失败,那么将执行这个 callback 让你添加一些容错逻辑
enableAliCDNSuffix是否启用 Ali CDN 自动裁切参数falsefalse如果在 cover 模式下,图片高度太高可能会拉伸的比较模糊

图片底部存在 3px 空隙的解决方法

如果你将当前组件用来展示图片放在其他组件内,或者使用当前组件时有外边线,细致的你会发现底部可能存在 3px 的间隙:

image

这是由于图片的 inline-block 渲染模式导致的,你无需理解背后的原理,如果你想去掉这个间隙,可以直接在当前组件加上一行 CSS 即可:

<Img
  style={{
    verticalAlign: 'middle',
  }}
  src="xxx"
/>

图片尺寸性能优化

图片原图可能会非常大,例如 https://img.alicdn.com/tps/TB1qfWuMVXXXXcEXpXXXXXXXXXX-434-254.png 会达到 200kb 但实际放在页面上,希望它只显示 200x100 这样的尺寸,此时性能就会很差。

如果你的图片使用 img.alicdn.com 这个 CDN 地址,那么可以传入 props enableAliCDNSuffix={true} 将自动开启 Ali CDN 裁切参数,会将图片 url 变成 https://img.alicdn.com/tps/TB1qfWuMVXXXXcEXpXXXXXXXXXX-434-254.png_400x200q90.jpg 进行压缩优化,压缩之后图片只有 116kb,加载性能会提升非常多,建议默认开启使用。

如果在 cover 模式下,如果图片尺寸跟配置的显示尺寸差距太大,可能会导致拉伸变模糊,如果绝大部分图片都是此类尺寸,可以设置 false 去掉这个功能。

allen-test-project@infinitebrahmanuniverse/nolb-_icedtt-comps@everything-registry/sub-chunk-450syfed-scaffoldtest-pro-scaffoldxinxuan-backstage-scaffoldice-assetsice-react-materialsice-react-materials-jimuice-design-ecommerceice-post-platfromharryyubloglzd-labnpmlqs-in-tiger-promaterial-qlxpmaterilas-gaia-ice-filtertablenm-react-apprhino-design-appsixue-img-uploadsixue-rules@aliretail/react-oms-delivery-sdkzhangzhexin-comps@halofe/cloud-admin-boilerplate@icedesign/admin-scaffold@icedesign/algorithm-model-admin-scaffold@icedesign/aliyun-login-scaffold@icedesign/application-management-admin-scaffold@icedesign/aside-layout@icedesign/asset-management-scaffold@icedesign/basic-layout@icedesign/builder-platfrom-scaffold@icedesign/contract-management-scaffold@icedesign/creator-admin-scaffold@icedesign/custom-react-scaffold@icedesign/customer-analysis-admin-scaffold@icedesign/dashboard-scaffold@icedesign/demo-layout@icedesign/ecommerce-scaffold@icedesign/enhance-table-block@icedesign/cms-scaffold@icedesign/commodity-management-scaffold@icedesign/complex-progress-table-block@icedesign/complex-tab-table-block@icedesign/brand-display-block@icedesign/usertrack-admin-scaffold@icedesign/voice-chat-admin-scaffold@icedesign/website-homepage-scaffold@icedesign/universal-homepage-scaffold@icedesign/user-landing-block@icedesign/user-profile-card-block@icedesign/ice-website-homepage@icedesign/government-management-admin@icedesign/header-aside-footer-layout@icedesign/header-aside-footer-responsive-layout@icedesign/header-footer-layout@icedesign/homepage-scaffold@icedesign/hospital-scaffold@icedesign/hr-management-admin-scaffold@icedesign/ice-admin@icedesign/ice-homepage@icedesign/layout-builder@icedesign/library-management-admin@icedesign/lite-scaffold@icedesign/monitor-dashboard@icedesign/picture-text-list-block@icedesign/post-platfrom-scaffold@icedesign/pro-scaffold@icedesign/operation-admin-scaffold@icedesign/operation-platform-scaffold@icedesign/operation-table-block@icedesign/order-management-scaffold@icedesign/filter-list-block@icedesign/filter-table-block@icedesign/fixed-header-footer-responsive-layout@icedesign/landing-layout@icedesign/reviews-management-scaffold@icedesign/scaffold-analytical@icedesign/scaffold-cms@icedesign/scaffold-ecommerce@icedesign/project-management-admin@icedesign/project-management-scaffold@icedesign/simple-table-block@icedesign/simple-video-player-block@icedesign/scafford-pro@icedesign/scalable-aside-layout@icedesign/schools-scaffold@icedesign/scaffold-ice-website-homepage@icedesign/scaffold-pro@icedesign/scaffold-project-management@icedesign/task-management-admin-scaffold@icedesign/template-builder@react-materials/user-landing-block@react-materials/user-profile-card-block@pipcook/pipboard@pipcook/pipcook-board-client@zalastax/nolb-_iceaui-demonewcwy-testfingo-data-list-block
1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.2

6 years ago

0.1.1

7 years ago

0.1.0

7 years ago