Skip to content

Instantly share code, notes, and snippets.

@jdltechworks
Created October 19, 2017 05:31
Show Gist options
  • Save jdltechworks/9f4414d55bbe8230d7c788b661d035a4 to your computer and use it in GitHub Desktop.
Save jdltechworks/9f4414d55bbe8230d7c788b661d035a4 to your computer and use it in GitHub Desktop.
Image loader sample
import React, { Component } from 'react'
export default class ShareThumbnail extends Component {
preloader(image) {
let { props } = this
let { src } = props
let loader = document.querySelector('.lazy-loader')
if( image !== null ) {
if( src ) {
image.style.display = 'none'
image.setAttribute('src', src)
loader.style.display = 'block'
image.onload = (e) => {
let { parentNode } = image
if(loader) {
setTimeout(() => {
image.style.display = 'block'
loader.style.display = 'none'
}, 200)
}
}
image.onerror = (e) => {
image.setAttribute('src', 'https://dummyimage.com/428x312/f8f8f8/ccc.png&text=Image+not+found')
}
}
}
}
render() {
return(
<div className="share-thumbnail well">
<div className="lazy-loader">
<div className="loader">
<div className="ball-grid-pulse">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div className="text">Making the chart ...</div>
</div>
</div>
<img className="loading" ref={this.preloader.bind(this)} />
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment