$ npm i scroll-horizontal
Import the script and call the HorizontalSection() function.
let newHorizontalSection = new HorizontalSection({
settings: {
offsetScroll: 500
}
}).init()
<div class="section-horizontal-scroll">
<div class="scroll-wrapper">
<div class="section-container">
<div class="line">
<!-- put your stuff here -->
</div>
</div>
</div>
</div>
settings: {
offsetScroll: 500, // scroll offset (in pixels) when entering and leaving the section (500 recommended)
disableBefore: 768, // sets minimum screen width to run
disableAfter: 1024, // sets max screen width to run
offsetPercent: 20 // integer - same as offsetScroll, but uses viewport width instead of pixels
}
If you want to use padding add this style to your css to fill right-side gap
.line::after {
content: '';
display: block;
width: 120px; /* padding */
height: 1px;
flex-shrink: 0;
}
View the example here
Check this implementation in an actual project
The package is still in development. However, it supports common browsers and devices including IE 11. Current version consists only of minified ES5 javascript file. Visit the repo for more.
- Transpile to vanilla
- Transpile to ES5
- Add minified version
- Run coverage tests
- Add mobile version support
- Add styles
- Create webpage
- Window resize support