Git Product home page Git Product logo

react-bhx-images's Introduction

react-bhx-images

React BHX images it's a component to deal with images in your React app. You can use this to preload images, preload background and fadein images only when it shows up using scroll.

Feat

  • Pre-load images
  • Pre-load image as background
  • fade-in images using scroll
  • Load image only when scrolls or preload and fade when scrolls
  • loading placeholder images
  • Pre-load external image
  • Pre-load internal images

Options

Not all properties are mandatory.

interface IProps {
	src: string;
	height?: number;
	width?: number;
	preload?: boolean;
	customClass?: string;
	scrollChecker?: string;
	background?: boolean;
	children?: React.ReactNode;
}

src

The source of the image

height x width

height and width of the content. not required but it's required if you need to have a placeholder to save the location before loading.

preload

default value: false

If it's true, the image is loaded before scrolling

customClass

A new class to the image

scrollChecker

the scrollChecker it's a function that receive the state to control which image needs to bind the scroll event.

// import the useImageScrolling
import ImageLoad, { useImageScrolling } from './components/ImageLoad';

// put it in some const
const scrollChecker = useImageScrolling();

// define
<ImageLoad
		src="https://media.fromsoftware.jp/eldenring/resources/images/movieandimages/screenshot/4k/02.jpg"
		height={100}
		width={150}
		scrollChecker={scrollChecker}
	/>

background

If you defined use this prop it means that the content is not a image but a background of something instead.

The content use the image to save the preload content and you can set it into something inside the component as children

<ImageLoad
	src="https://media.fromsoftware.jp/eldenring/resources/images/movieandimages/screenshot/4k/01.jpg"
	height={200}
	width={250}
	background
>
	<div
		className="background-sample"
		style={{
			backgroundImage:
				'url(https://media.fromsoftware.jp/eldenring/resources/images/movieandimages/screenshot/4k/01.jpg)',
		}}
	>
		<p>IMAGE AS BACKGROUND</p>
	</div>
</ImageLoad>

Example

preaload.gif

react-bhx-images's People

Contributors

coffezilla avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.