
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
react-hover-slideshow
Advanced tools
Iterates through an image slideshow based on cursor position
Iterates through an image slideshow based on cursor/touch position.
See the Storybook examples
react-hover-slideshow
is distributed via npm which comes with Node. To install it as a dependency of your project, simply navigate to your project directory and run:
npm i --save react-hover-slideshow
This module also depends on your project already having react
and prop-types
as peer dependencies. If you don't yet have those, you can add them as dependencies of your project with this:
npm i --save react prop-types
⚠️Warning!⚠️ - this code uses Hooks under the hood, which was introduced in React 16.8. This code will not work with older versions of React.
The simplest way to use react-hover-slideshow
is to use the HoverSlideshow
component:
import React from "react";
import { HoverSlideshow } from "react-hover-slideshow";
// As a function component
function MyFunctionComponent(props) {
const imageURLs = [
"https://example.com/1.jpg",
"https://example.com/2.jpg",
"https://example.com/3.jpg"
];
return (
<div>
<h3>My photo album</h3>
<HoverSlideshow
aria-label="My pretty picture slideshow"
images={imageURLs}
width="400px"
height="300px"
/>
</div>
);
}
// Or as a class component
class MyClassComponent extends React.Component {
render() {
const imageURLs = [
"https://example.com/1.jpg",
"https://example.com/2.jpg",
"https://example.com/3.jpg"
];
return (
<div>
<h3>My photo album</h3>
<HoverSlideshow
aria-label="My pretty picture slideshow"
images={imageURLs}
width="400px"
height="300px"
/>
</div>
);
}
}
Alternatively you can use HoverSlideshowAnimated
with the same interface, which will give you a nice crossfade effect. Note that this animated variation depends on the peer dependency react-transition-group
, which you can add you your project with the following:
npm i --save react-transition-group
Behind the scenes, the helper components above use the hook useHoverSlideshow
. If you wish for more control over the image component markup and CSS, I recommend making a copy of /src/HoverSlideshow.js
and making this small change:
import React from "react";
import PropTypes from "prop-types";
-import useHoverSlideshow from "./useHoverSlideshow";
+import { useHoverSlideshow } from "react-hover-slideshow";
Then simply use that code as a baseline, and tweak what you like! Here's a quick guide of what's happening in the hook:
currentImage
- determined by figuring out the user's "cursor progress" over an element, then finding the closest match in the images
array passed in. For instance, if images
contains two image hrefs, the first image will display until the user's cursor passes over 50% of the element (where 50% is defined horizontally by default).
updateHoverSlideshow
- updates currentImage
based on mousemove
and touchmove
events
resetHoverSlideshow
- should be called when the user is no longer interacting with the element (mouseout
or touchend
). Resets by displaying the first image in the array.
git clone git@github.com:davidcalhoun/react-hover-slideshow.git
cd react-hover-slideshow
npm i
scripts
section in package.json
for a list of available dev commands.FAQs
Iterates through an image slideshow based on cursor position
The npm package react-hover-slideshow receives a total of 17 weekly downloads. As such, react-hover-slideshow popularity was classified as not popular.
We found that react-hover-slideshow demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.