2.0.3 • Published 2 years ago

@afiniti/parallax-slider v2.0.3

Weekly downloads
67
License
MIT
Repository
gitlab
Last release
2 years ago

@afiniti/parallax-slider

Description

React slider component for images and videos. It provides option for parallax effects for sliding animations.

Note

This is a work in progress, not ready for production yet. Your feedback would be appreciated, custom features can also be requested.

Requirements

Currently, works only for image urls from graph media cms. Support for other image sources will be added as enhanced feature later on.

Installation

npm i @afiniti/parallax-slider

Features

  • Fullscreen slider
  • Handles both images and videos.
  • Parallax sliding effects
  • Scroll to slide using mouse and trackpad
  • Multiple callbacks for as much customization as possible
  • Memory and performance optimization: pauses automatically if the current browser tab is inactive or if the browser itself is inactive.

Props

NameTypeDescription
dataobjectImage or video sources in specified format.
autoplayboolAutoplay slider or not. Defaults to true
iterationsnumberNumber of iterations in case of autoplay. Defaults to infinite/null
slideSpeednumberDuration in milisecond for slide enter/exit animation. Defaults to 1.6
scrollToSlideboolChange slides on mouse/trackpad scroll. Defaults to false.
autoplaySpeednumberDuration in miliseconds for which each slide stays on screen. Defaults to 3000
tiltBackgroundboolTilt effect on hover. Defaults to false
initialSlideIndexnumberOptional value in pixels if fixed height needs to be added to image elements.

Methods

NameDescription
pausePause the slider if autoplay enabled. slider.pause()
resumeResume the slider if autoplay enabled. slider.resume()
slideToTransitions to slide with index provided. slider.slideTo(3)
isPausedReturns if the autoplay is paused. slider.isPaused()
isSlidingReturns if the sliding animation is in progress. slider.isSliding()
slideNextNumber of iterations in case of autoplay. infinite/null
currentIndexReturns index of active slide. slider.currentIndex()
slidePreviousOptional value in pixels if fixed height needs to be added to image elements.
isIterateableReturns if the slider has completed given iterations. slider.isIterateable()
updateScrollToSlideUpdates inital prop value given for scrollToSlide prop. slider.isIterateable()
updateTiltBackgroundUpdates inital prop value for updateTiltBackground. slider.updateTiltBackground()

Callbacks

NameDescription
parallaxSliderApiReturns reference object for Slider API.
onSlideStartCalled on start of every slide transition onSlideStart(currentIndex, nextIndex, direction)
onSlideCompleteCalled on end of every slide transition onSlideComplete()

Example Usage

The package can be integrated inside a react component as follows:

import React, { useRef } from 'react';
import ParallaxSlider from '@afiniti/parallax-slider';

const data={
  {title: "Image 1", Picturehandle: "LCcgeYuDSmeZZPu0hWRo"},
  {title: "Image 2", Picturehandle: "LCcgeYuDSmeZZPu0hWRo"},
  {title: "Image 3", Picturehandle: "LCcgeYuDSmeZZPu0hWRo"}
};

const Component = () => {
  const parallaxSliderApi = useRef();

  return (
    <ParallaxSlider
      autoplay
      data={data}
      scrollToSlide
      iterations={2}
      tiltBackground
      initialSlideIndex={0}
      parallaxSliderApi={ref => {
        parallaxSliderApi.current = ref;
      }}
      onSlideStart={(currentIndex, nextIndex, direction) => {}}
    />
  );
};

export default Component;
2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.3

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago