@lxfriday/smooth-scroll-to
v1.0.1
Published
smooth scroll to somewhere
Downloads
3
Readme
@lxfriday/smooth-scroll-to
javascript scroll for anywhere
install
npm i @lxfriday/smooth-scroll-to -S
# or
yarn add @lxfriday/smooth-scroll-to
params
smoothScrollTo(ref, pos[, rate])
ref
{HTMLElement
}required
, the component you want to scrollpos
{number
}required
, the component you want to scrollrate
{numbger
} scroll speed, bigger means faster
usage
// use in react
import React, { Component } from 'react';
import smoothScrollTo from '@lxfriday/smooth-scroll-to';
class Scroll extends Component {
handleScroll = () => {
smoothScrollTo(this.scroll, 1000)
}
render() {
return (
<div ref={r => (this.scroll = r)} style={{ height: 700 }}>
<button onClick={this.handleScroll}>scroll go</button>
<div style={{ height: 5000 }}>
<div style={{ height: 300, backgroundColor: 'red' }} />
<div style={{ height: 300, backgroundColor: 'green' }} />
<div style={{ height: 300, backgroundColor: 'yellow' }} />
<div style={{ height: 300, backgroundColor: 'red' }} />
<div style={{ height: 300, backgroundColor: 'green' }} />
<div style={{ height: 300, backgroundColor: 'yellow' }} />
<div style={{ height: 300, backgroundColor: 'red' }} />
<div style={{ height: 300, backgroundColor: 'green' }} />
<div style={{ height: 300, backgroundColor: 'yellow' }} />
<div style={{ height: 300, backgroundColor: 'red' }} />
<div style={{ height: 300, backgroundColor: 'green' }} />
<div style={{ height: 300, backgroundColor: 'yellow' }} />
<div style={{ height: 300, backgroundColor: 'red' }} />
<div style={{ height: 300, backgroundColor: 'green' }} />
<div style={{ height: 300, backgroundColor: 'yellow' }} />
</div>
</div>
)
}
}