legitcode / image Goto Github PK
View Code? Open in Web Editor NEWan img tag, with lazy loading
Home Page: http://legitcode.github.io/image/
an img tag, with lazy loading
Home Page: http://legitcode.github.io/image/
Check if the image tag is close to the scroll height and only load it at that point. Make this an optional prop
Hi :)
When I use your component, I get this error message:
Uncaught Error: A valid ReactComponent must be returned.
Figured, this happens because React is considering the component only valid if its enclosed in div tags. So when changing your code as below, things work properly well.
return (
<div>
<img
{...this.props}
style={style}
src={this.props.src}
onLoad={this.fadeIn}
/>
</div>
)
When using the react-redux-universal-hot-example repo as a starting point (https://github.com/erikras/react-redux-universal-hot-example/tree/4705688b879f853ede08e3872bc083cc84227824)
My component:
<Image className="thumbnail" src="https://i.imgur.com/l50kGUz.png" />
The HTML that comes through in the view source:
<img class="thumbnail" src="https://images.unsplash.com/photo-1439003511744-2a0490ea0a88?q=80&fm=jpg&s=4dd5809698048edf8b82eedb82ca8cec" style="transition:opacity 1s;opacity:0;" data-reactid=".mzv5v08jcw.2.0.0.0">
Notice how the opacity is frozen at 0.
How to reproduce:
npm i --save legit-image
npm start
Race condition with server-side rendering?
This component needs more work to really be future-proof. Expect a pr from me soon.
it makes sense to support those. you probably won't need any transitions in that case.
I'm not quite sure what the intention was with the first part of this line:
if(!src.match(/http/) || typeof window === 'undefined') opacity = 1
Basically that means you won't get fading images for:
<LegitImage src="foo.jpg" />
)<LegitImage src="//domain.com/foo.jpg" />
)Using peer dependency causes it to break in react 0.14.8
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.