0.0.4 • Published 4 years ago

@afiniti/webgl-slider v0.0.4

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
4 years ago

@afiniti/webgl-slider

Description

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

Requirements

Currently, works only for images and videos.

Installation

npm i @afiniti/webgl-slider

Features

  • Fullscreen slider
  • Handles both images and videos.
  • Webgl transition effects.
  • Multiple callbacks for as much customization as possible

Props

NameTypeDescription
fpsnumberIn order to keep performance in mind if it is a video carousel then use your desired fps to keep memory and cpu usage as less as possible. Defaults to null it will collect browser refresh rate.
dataobjectImage or video sources in specified format.
effectnumberCurrently 8 different types of webgl effects are available pass number between 1 to 8.
iterationsnumberNumber of iterations in case of autoplay. Defaults to infinite/null
autoplayboolAutoplay slider or not. Defaults to true
autoplaySpeednumberSet autoplay slide speed . Defaults to 3000 3 seconds
slideSpeedfloatSet slide effect speed. Defaults to 1.6 1.6 seconds
scrollToSlideboolChange slides on mouse/trackpad scroll. Defaults to false.
initialSlideIndexnumberOptional value in pixels if fixed height needs to be added to image elements.

Methods

NameArgsDescription
pausenonePause the autoplay.
resumenoneStart the autoplay.
pauseRendernonePause requestanimationframe to save battery and memory.
resumeRendernoneResume requestanimationframe.
SlideNextnoneGo to the next slide.
slidePreviousnoneGo to the previous slide.
updateScrollToSlidetrue/falseEnable/Disable slides Change on mouse/trackpad scroll

Callbacks

NameDescription
onSlideStartreturns currentIndex, nextIndex, direction, Triggers on slide start
onSlideCompletereturns nothing, Trigger when slide ends
webglSliderApireturn ref of the slider to give access to all available methods

Example Usage

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

import React from 'react';
import WebglSlider from '@afiniti/webgl-slider';

const data={
  {Picturehandle: "https://images.unsplash.com/photo-1603993097397-89c963e325c7?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80"},
  {Picturehandle: "https://images.unsplash.com/photo-1618580987827-8d73bdd196aa?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1489&q=80"},
  {Picturehandle: "https://images.unsplash.com/photo-1593642632823-8f785ba67e45?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1489&q=80"}
};

OR

const data={
  {videoHandle: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"},
  {videoHandle: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"},
  {videoHandle: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"}
};

// you can get public test videos from here: https://gist.github.com/jsturgis/3b19447b304616f18657

const Component = () => {
  return (
    <WebglSlider
      fps={25}
      autoplay
      effect={4} // give number between 1 to 8
      iterations={2}
      slideSpeed={1.6}
      data={webglData}
      autoplaySpeed={8000}
      initialSlideIndex={0}
      onSlideStart={(currentIndex, nextIndex, direction) => {
        console.log(currentIndex, nextIndex, direction);
      }}
      onSlideComplete={() => {
        console.log('complete');
      }}
      webglSliderApi={ref => {
        // get access to slider's methods
        console.log('ref', ref);
      }}
    />
  );
};

export default Component;