3.0.0 • Published 5 months ago

sheet-slider v3.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

SheetSlider

Features

  • Pure and modern CSS
  • No dependencies
  • Lightweight (minified ~ 1kb with Brotli)
  • Fast and smooth
  • Responsive (intrinsic ratio)
  • Customizable with CSS and Sass variables
  • Easy to use
  • Multiple sliders on the same page
  • Open source

Install

npm

npm install sheet-slider

CDN

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sheet-slider@3/dist/main.min.css"/>

How to use

The slider only needs a basic HTML structure to work:

<div class="sheet">
  <input id="a1" type="radio" name="a" checked>
  <input id="a2" type="radio" name="a">
  <input id="a3" type="radio" name="a">
  <div class="sheet-content">
    <div class="sheet-item">
      <img class="sheet-image" src="image.jpg">
    </div>
    <div class="sheet-item">
      <img class="sheet-image" src="image.jpg">
    </div>
    <div class="sheet-item">
      <img class="sheet-image" src="image.jpg">
    </div>
  </div>
  <div class="sheet-arrows">
    <label for="a1"></label>
    <label for="a2"></label>
    <label for="a3"></label>
  </div>
</div>

All content inside the sheet-item elements will be the ones that move. They don't necessarily have to be images, they can be any HTML element.

The slider also has two optional elements, which are the navigation buttons and the descriptive texts. If you include them, the structure would look like this:

<div class="sheet">
  <input id="a1" type="radio" name="a" checked>
  <input id="a2" type="radio" name="a">
  <input id="a3" type="radio" name="a">
  <div class="sheet-content">
    <div class="sheet-item">
      <img class="sheet-image" src="image.jpg">
      <!-- description -->
      <div class="sheet-meta">
        <h4 class="sheet-title">Example title</h4>
        <p class="sheet-text">Text description</p>
      </div>
    </div>
    <div class="sheet-item">
      <img class="sheet-image" src="image.jpg">
      <!-- description -->
      <div class="sheet-meta">
        <h4 class="sheet-title">Example title</h4>
        <p class="sheet-text">Text description</p>
      </div>
    </div>
    <div class="sheet-item">
      <img class="sheet-image" src="image.jpg">
      <!-- description -->
      <div class="sheet-meta">
        <h4 class="sheet-title">Example title</h4>
        <p class="sheet-text">Text description</p>
      </div>
    </div>
  </div>
  <!-- dots -->
  <div class="sheet-dots">
    <label for="a1"></label>
    <label for="a2"></label>
    <label for="a3"></label>
  </div>
  <!-- arrows -->
  <div class="sheet-arrows">
    <label for="a1"></label>
    <label for="a2"></label>
    <label for="a3"></label>
  </div>
</div>

Note: The for attribute of the labels must match the id of the inputs. For multiple sliders on the same page, the name attribute of the inputs must be different, and the for attribute of the labels must match the id of the inputs of the slider to which they belong.

Customize

Define new values for the variables in your CSS file or in the :root selector.

VariableDescription
--sheet-accentAccent color
--sheet-spaceSpace of the elements
--sheet-arrow-sizeSize of the arrows
--sheet-durationAnimation duration
--sheet-dot-sizeSize of the dots
--sheet-timingAnimation timing function
--sheet-text-colorText color
--sheet-text-shadowText shadow
--sheet-title-sizeTitle font size
--sheet-text-sizeText font size
--sheet-arrow-paddingPadding of the arrows
--sheet-arrow-bgBG color of the arrows
--sheet-arrowSVG of the arrows
--sheet-dot-gapSpace between the dots
--sheet-dot-bgBG color of the dots
--sheet-dot-hoverBG color of the dots when hover

You can also modify the values in the _variables.scss file and compile it with Sass.

Options

You can choose between two animation modes: fade and vertical. By default, the animation mode is horizontal. If you want to change it, you just have to add the corresponding class to the main container:

<div class="sheet sheet-fade">
  ...
</div>
<div class="sheet sheet-vertical">
  ...
</div>

Supporting

If you want to help me keep this and more related projects always up to date, you can buy me a coffee ☕. I will be very grateful 👏.

License

Sheet Slider is licensed under the MIT License

3.0.0

5 months ago