yosbelms / react-progressive-loader

Utility to load images and React components progressively, and get code splitting for free
217 stars 12 forks source link

Remove redundant dom in Img component #9

Closed felixmosh closed 5 years ago

felixmosh commented 5 years ago

There is no need for the last div in order to preserve the image ration, the bg div can be used as the aspect ratio preserver.

BTW, the best approach of aspect ratio preservation is by using pseudo element, I guess that you didn't used this approach because all your styles are inline.

.lazy-loaded {
    position:relative;
}
.lazy-loaded:after {
    padding-top: var(--aspectRatio);
    width: 100%;
    content: '';
    display:block;
}
<div data-wrapper class="lazy-loaded" style={{ '--aspectRatio': '70%' }}>
  <img src="...." />
</div>
felixmosh commented 5 years ago

I want to reduce the amount of dom element cause I have a long list of lazy loaded images.