New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@fylgja/scroll-slider

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fylgja/scroll-slider

The Fylgja scroll-slider component

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
20
decreased by-16.67%
Maintainers
1
Weekly downloads
 
Created
Source

Fylgja - Scroll-slider

NPM version license

This CSS slider component allows you to make sliders with ease, and has no requirements to any Javascript.

The only reason to add some additional Javascript, would be to add extra supporting functions.

Like a navigation and a active state.

Installation

npm install @fylgja/scroll-slider

Then include the component in to your code via;

@use "@fylgja/scroll-slider";
// Or via PostCSS and other options as plain CSS
@import "@fylgja/scroll-slider/scroll-slider.css";

How to use

To create a slider, you will need a wrapper element with the class .scroll-slider.

Any direct children of the slider will become scroll items.

<div class="scroll-slider">
    <div>..</div>
    <img src="">
</div>

The scroll items will by default have the size from the content.

If you want your slides to have a specific size, you can use the CSS variables provided by this CSS component.

A full width slider can be made by setting the scroll-size to 100% and setting the inline gap to 0.

If you also want to reserve the scroll gap, set the block gap to whatever your want.

<style>
    .scroll-slider.-full-slide {
        --scroll-size: 100%;
        --gap-inline: 0;
    }
</style>
<div class="scroll-slider -full-slide">
    <div>..</div>
    <img src="">
</div>

Config

Want more control on the base styles, then the CSS variables, here are the following SCSS variables you can modify.

$enable-scroll-overflow-fix: true !default;

$scroll-gap: 0.5em !default;
$scroll-padding-y: 1rem !default;
$scroll-padding-x: 1.25rem !default;

// Item
$scroll-align: center !default;
$scroll-stop: always !default;
$scroll-stop-fine: normal !default;

Tips

Down here some useful tips to enhance your slider.

Adding a navigation

You can create a navigation for the slider, by using an anchor hash link pagination,

and using the @fylgja/pagination as CSS component for the style.

If don't like the hash to appear in your url, you can add a little javascript to enhance this behavior,

and remove the hash from your url.

Example of the HTML and Javascript pagination
<div class="scroll-slider">
    <div id="scroll-item-1">..</div>
    <div id="scroll-item-2">..</div>
</div>
<div class="pagination my-1" aria-label="pagination">
    <a href="#scroll-item-1" class="pagination-link" onclick="scrollToElement()">
        <span><span class="aria-hidden">Go to slide </span>1</span>
    </a>
    <a href="#scroll-item-2" class="pagination-link" onclick="scrollToElement()">
        <span><span class="aria-hidden">Go to slide </span>2</span>
    </a>
</div>
<script>
    const scrollToElement = () => {
        const id = event.target.attributes.href.value.split("#")[1];
        event.preventDefault();
        document.getElementById(id).scrollIntoView();
    }
</script>

An event listener would have been better. But this is just sample 😉

Hiding or Changing the scrollbar

By default we don't hide or change the scrollbar.

If you slider requires a more custom style use the @fylgja/scrollbar component, adding the thin or hide class.

Keywords

FAQs

Package last updated on 10 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc