New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

before-after

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

before-after

BeforeAfter is a lightweight Javascript library to compare images in before/after view without any dependencies

latest
Source
npmnpm
Version
4.0.0
Version published
Weekly downloads
6
50%
Maintainers
1
Weekly downloads
 
Created
Source

beforeAfter

GitHub Workflow Status (branch)

before-after is a lightweight Javascript library to compare images in before/after view. The new version of the library does not use any dependencies.

Installation

NPM

NPM is the recommended installation method. Install before-after in your project with the following command:

npm install before-after --save-dev
yarn add before-after --dev

Warning before-after@3 is ESM.

Note Minimum supported Node.js version is 22.

Installation

The library is available as the before-after package name on npm and Github.

npm install before-after --save
yarn add before-after --dev

How it works

HTML

<div class="beforeafter">
  <img src="img/before.jpg" />
  <img src="img/after.jpg" />
</div>

Note The last image will be on the top

Initialization

Import before-after JavaScript library as an ES6 modules.

import BeforeAfter from 'before-after';

The before-after constructor accepts the following parameters:

ArgumentsTypeDefaultDescription
elementHTMLElementnullHTMLElement to target the library
configObject{}Configuration (optional)

Initialize the library with a CSS selector string.

new BeforeAfter(document.querySelector('.beforeafter'));

Configuration

Options

cursor

Type:

type cursor = boolean;

Default: true

Tells the library to enable the cursor following mouse or finger.

new BeforeAfter(document.querySelector('.beforeafter'), {
  cursor: false
});

orientation

Type:

type orientation = 'horizontal' | 'vertical';

Default: 'horizontal'

Tells the library which orientation used.

new BeforeAfter(document.querySelector('.beforeafter'), {
  orientation: 'vertical'
});

start

Type:

type start = number;

Default: 50

Tells the library the start position.

new BeforeAfter(document.querySelector('.beforeafter'), {
  start: 30
});

Methods

destroy

Tells the library to destroy the instance.

beforeAfter.destroy();

License

before-after is licensed under the MIT License.

Created with ♥ by @yoriiis.

Keywords

slider

FAQs

Package last updated on 20 Feb 2026

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