Giter Club home page Giter Club logo

img-comparison-slider's Introduction

img-comparison-slider

npm package Published on webcomponents.org

Slider component for comparing images (before and after).

Usage examples: https://img-comparison-slider.sneas.io/examples.html

Example

Key Features

  • Mobile friendly
  • Accessible
  • Responsive
  • Compact - less than 9 kB minified (Or less than 3 kB when gzipped)
  • Compatible with modern frameworks (React, Angular, Vue2, Vue3)
  • Distributed through CDN or NPM

Installation

HTML

<script
  defer
  src="https://unpkg.com/img-comparison-slider@7/dist/index.js"
></script>
<link
  rel="stylesheet"
  href="https://unpkg.com/img-comparison-slider@7/dist/styles.css"
/>

<img-comparison-slider>
  <img slot="first" src="before.jpg" />
  <img slot="second" src="after.jpg" />
</img-comparison-slider>

Frameworks Support

Supported Attributes

Besides the default HTMLElement attributes such as class, tabindex, title, etc., img-comparison-slider supports:

Attribute Description Default Available
value Position of the divider in percents. 50 0..100

Styling

Some styling techniques and ideas could be found in examples.

The component items such as the default handle or divider could be styled with the help of CSS3 variables.

Example:

<style type="text/css">
  img-comparison-slider {
    --divider-width: 2px;
    --divider-color: #c0c0c0;
    --default-handle-opacity: 0.3;
  }
</style>

Available Variables

Variable Description Default value Example value
--divider-width Width of the vertical line dividing both images 1px 1em
--divider-color Color of the vertical line dividing both images #fff rgba(0, 0, 0, 0.5)
--divider-shadow Shadow casting by the vertical line dividing both images none 0px 0px 5px rgba(0, 0, 0, 0.5)
--default-handle-width Width of the default handle 50px
--default-handle-color Color of the default handle #fff rgba(0, 0, 0, 0.5)
--default-handle-opacity Opacity of the default handle 1 0.3
--default-handle-shadow Shadow from the default handle none 0px 0px 5px rgba(0, 0, 0, 1)

Handle

The component's handle could be changed by assigning slot="handle" attribute to any element inside img-comparison-slider.

img-comparison-slider's People

Contributors

sneas avatar semantic-release-bot avatar dependabot[bot] avatar realaestan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.