Skip to content

Instantly share code, notes, and snippets.

@yano3nora
Last active June 6, 2023 10:30
Show Gist options
  • Save yano3nora/c8416c4ab0472a520908d776d3ca5c5d to your computer and use it in GitHub Desktop.
Save yano3nora/c8416c4ab0472a520908d776d3ca5c5d to your computer and use it in GitHub Desktop.
Fix Aspect on Loading Image by native Width & Height Attributes. #css
/**
* @link https://parashuto.com/rriver/development/img-size-attributes-are-back
*/
import { Image } from '@chakra-ui/react'
export const myComponent = () => (
// chakra image には元々 max-width: 100%; height: auto があたってる
<Image
src={'/some-large-image.png'}
// native attributes である width, height に元画像のサイズなどを入れると
// 画像の読み込み中でも、その aspect を保ったまま (高さを保持したまま) 表示され
// 結果的に ui jank (レイアウトシフト、画面のガタツキ) が発生しない
htmlWidth={1920}
htmlHeight={1080}
/>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment