npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

image-before-after

v1.0.27

Published

Component for the web adding easy comparing of image before and after

Downloads

14

Readme

image-before-after

Sometimes you want to be able to compare two images, showing the before and after version of the image.

Say you have spend 30 minutes in Snapseed producing a beautifully manipulated version of the original raw image, you would like to show the world the result (after) image and the original (before image on top of each other, letting the visitor drag over the image and instantly see the difference.

Demo

Alt text

You can try out the javascript class version at codepen.

Installation

Using NPM: npm install image-before-after

Documentation

There will be these versions of the component:

  • Javacript Class based
  • Webcomponent: <image-before-after />

Using it can be seen here

Vanilla JS

To use it you should new the class ImageBeforeAfter with these parameters:

| Parameter | required | Type | Description | | --------- | -------- | ------------------------- | ------------------------------------------------------------------ | | selector | yes | CSS selector string | A CSS selector to an element you want to add the functionallity to | | before | no | string | URL to the before image | | after | no | string | URL to the after image | | text | no | string | A text to show on top of the images | | width | no | valid css width or number | The width you want the compoment to be |

Simply import the component and inserting it into the html element with the class IBA:

HTML

<div class="IBA"></div>

Javascript

<script type="text/javascript">
const before = 'https://dummyimage.com/600x400/000/fff.png';
const after = 'https://dummyimage.com/600x400/ffffff/000.png';

const myIBA = new ImageBeforeAfter('.IBA', before, after, 'Inverted example');
</script>

Use webcomponent/CustomElement in a HTML page

The webcomponent or customElement <imgage-before-after /> can be easily used in any modern browser, simply by importing the code like this:

import imageBeforeAfter from "https://cdn.skypack.dev/[email protected]";

After this your browser knows about the new HTML element, or tag: image-before-after and you simply can use it as any other native HTML element.

You can see an example CustomEement image-before-after

Angular

See running demo on Stackblitz.com.

Add the package to your project:

npm install image-before-after

In the main.ts add a reference to the package:

import 'image-before-after';

This will allow you to use the customElement anywhere in your project.

In the 'app.module.ts':

Add the CUSTOM_ELEMENTS_SCHEMA from the @angular/core and add it to the scemas in the @NgModule

import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { BrowserModule } from '@angular/platform-browser';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  providers: [],
  bootstrap: [AppComponent],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class AppModule {}

Contributing

You are welcome to report Issues and add feature request.

License

Image-before-after is ISC licenced