2.0.2 • Published 3 years ago

cubic-scroll-to v2.0.2

Weekly downloads
44
License
ISC
Repository
github
Last release
3 years ago

cubic-scroll-to

scrollTo with transition effect;

It's as simple and powerful as using the CSS cubic-bezier() function.Parameter generation

Why

  1. other libraries need complex calculation if they want to control rolling speed. This library implements cubic Bezier formula. You can customize the rolling effect you want by simply passing in parameters like CSS cubic-bezier().

Install

npm i cubic-scroll-to

Usage

import cubicScrollTo from "cubic-scroll-to";

const el = document.querySelector(".scroll-box");
const option = {
  el: el,
  cubic: [0.75, 0.16, 0.27, 0.88],
  totalTime: 2000,
};
const cubic = new cubicScrollTo(option);
cubic.scrollTo(500, 1000);

Options

Init

parameterexplaintypedefault
elParent elementElementwindow
cubicBezier curve parametersArray0.35, 0.13, 0.42, 1(https://cubic-bezier.com/#.17,.67,.83,.67)
totalTimeRolling timeNumber500

scrollTo(recommend)

Use current position as the starting point of rolling

const cubic = new cubicScrollTo();
cubic.scrollTo(500, 1000);
parameterexplaintypedefault
targetPositionXX-axis coordinate of target positionNumber0
targetPositionYY-axis coordinate of target positionNumber0

scrollToX

Scroll horizontally, customize the start and end X-axis positions

const cubic = new cubicScrollTo();
cubic.scrollToX(500, 1000);
parameterexplaintypedefault
currentPositionXThe x-axis coordinate of the current positionNumberX-axis coordinate of current position
targetPositionXX-axis coordinate of target positionNumber0

scrollToY

Scroll vertically to customize the start and end Y-axis positions

const cubic = new cubicScrollTo();
cubic.scrollToY(500, 1000);
parameterexplaintypedefault
currentPositionYY-axis coordinate of current positionNumberY-axis coordinates of current position
targetPositionYY-axis coordinate of target positionNumber0

scrollFromTo

Define the start and end coordinate points of the input

const cubic = new cubicScrollTo();
cubic.scrollFromTo({ x: 0, y: 0 }, { x: 500, y: 500 });
parameterexplaintypedefault
currentPositionThe coordinates of the current position pointObjectCurrent position coordinate point
targetPositionCoordinates of the target location pointObject{x:0,y:0}

Other

Open the test folder and view it test.html File for more use cases.

welcome star

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago