2.5.1 ā€¢ Published 3 years ago

@yaireo/fakescroll v2.5.1

Weekly downloads
62
License
-
Repository
github
Last release
3 years ago
  • 1.4KB gzipped (js)
  • 4.0KB minified (js)
  • 7.7KB unminified (js)
  • ~20+ KB avarage similar scripts (unminified)

Currently only supports vertical scroll due to cultural norms

While there is somewhat of a support for scrollbar customization through CSS, it is not fully supported in all browsers / older versions and the level of customization isn't flexible enough to allow creativity or certain special product needs.

šŸ‘‰ Make sure to import fakescroll.css

React port

import FakeScroll from '@yaireo/fakescroll/react.fakescroll.js'
import '@yaireo/fakescroll/fakescroll.css'

const onFakeScrollChange = ({ scrollRatio }) => console.log(scrollRatio)

<FakeScroll className='foo' track='smooth' onChange={onFakeScrollChange}>
    ...
</FakeScroll>

Example markup:

<div class="foo">
    ...
    ...
    ...
</div>

Initialize custom scrollbar with callback:

var myScrollbar = document.querySelector('.foo').fakeScroll({
    onChange: () => console.log( myScrollbar.scrollRatio )
})

The onChange also has a scrollRatio propery in its argument:

document.querySelector('.foo--outside').fakeScroll({
    onChange: ({ scrollRatio }) => console.log( scrollRatio )
});

The above markup will now become:

<div class="foo fakeScroll fakeScroll--hasBar">
    <div class="fakeScroll__wrap">
        <div class="fakeScroll__content">
            ...
            ...
            ...
        </div>
    </div>
    <div class="fakeScroll__bar"></div>
</div>

Browser support

The script probably won't work on IE without Babel & ES2015 polyfills.

DEMO PAGE

Settings

NameTypeDefaultInfo
classnameString""Class name which is added to the scrollbar Track element
trackBoolean/Stringfalseenable track events. use "smooth" for smooth "jumping"
onChangeFunctionCallback function whenever the scroll updates
2.5.0

3 years ago

2.5.1

3 years ago

2.2.1

3 years ago

2.2.0

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago