Git Product home page Git Product logo

jquery-images-compare's Introduction

jQuery Images Compare

A jquery plugin for comparing two images

jquery images compare preview

Badges

Scrutinizer Build Status Scrutinizer Code Quality GitHub tag GitHub release npm license

Features

  • compatibility : ie9+

  • Effort to put appearance via css (easier to skin / override)

  • Touch friendly, mouse drag, with a big thanks to Hammerjs :)

  • Responsive

  • You can listen to change event to add some of your logic

  • You can change the value from external code

  • Animation option when changing the value

  • Optional alternative interaction modes : drag by default (the recommended one), click and mousemove (warning desktop friendly only for this settings)

  • Size : ~2k of js and ~0.5k of css (minified and gzipped)

NB : This library only does horizontal slide

Quick start

In your head section, include the css (a minified version is also provided) :

<link rel="stylesheet" href="images-compare.css">

Include the required javascript, before the body closing tag :

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js"></script>
<script type="text/javascript" src="jquery.images-compare.min.js"></script>

Setup your html (minimal example) :

<!-- Main div container -->
<div id="myImageCompare">
    <!-- The first div will be the front element, to prevent FOUC add a style="display: none;" -->
    <div style="display: none;">
        <img src="assets/img/before.jpg" alt="Before">
    </div>
    <!-- This div will be the back element -->
    <div>
        <img src="assets/img/after.jpg" alt="After">
    </div>
</div>

Call the plugin :

$('#myImageCompare').imagesCompare();

Documentation

Install via npm

You can get the project via npm too :

npm install jquery-images-compare

Plugin settings

You can change plugin settings by passing an option object, example :

$('#myImageCompare').imagesCompare({
    initVisibleRatio: 0.2,
    interactionMode: "mousemove",
    addSeparator: false,
    addDragHandle: false,
    animationDuration: 450,
    animationEasing: "linear",
    precision: 2
});

List of available options :

key Description Default value
initVisibleRatio Visible ratio of front element on init, float value between 0 and 1 0.5 (front element is half visible)
interactionMode The interaction mode to use, valid values are "drag" (recommended), "mousemove", "click" "drag"
addSeparator Add a html separator element ? (thin vertical blank line) - boolean true
addDragHandle Add a html "drag handle" element ? - boolean true
animationDuration default animation duration in ms 400
animationEasing default animation easing to use ("linear", "swing") "swing"
precision Ratio precision, numbers after the decimal point 4

Changing appearance

The styling is done via css, to let you change it by css overrides.

Css classes

Basic list of main css classes, for full details please have a look at the css file.

Selector Description
.images-compare-container Container of the elements
.images-compare-before Front element
.images-compare-after Back element
.images-compare-separator Separator (thin vertical blank line)
.images-compare-handle Drag handle (circle)
.images-compare-left-arrow, .images-compare-right-arrow Drag handle arrows
.images-compare-label Label class element

Markup example with labels

You can add labels, add the class images-compare-label to your elements.

A default styling will be applied, you can override css rules to customize to your needs.

<!-- Main div container -->
<div id="myImageCompare">
    <!-- The first div will be the front element, to prevent FOUC add a style="display: none;" -->
    <div style="display: none;">
        <span class="images-compare-label">Before</span>
        <img src="assets/img/before.jpg" alt="Before">
    </div>
    <!-- This div will be the back element -->
    <div>
        <span class="images-compare-label">After</span>
        <img src="assets/img/after.jpg" alt="After">
    </div>
</div>

Events

List of events the plugin triggers :

Event name Description
imagesCompare:initialised This event is fired when init is done
imagesCompare:changed This event is fired when the value of visible front element is changed
imagesCompare:resized This event is fired when a resize window event has been received and treated

Example listening to change event

// important call data('imagesCompare') to get the real object and not the jquery one
var test = $('#myImageCompare').imagesCompare().data('imagesCompare');

test.on('imagesCompare:changed', function (event) {
    console.log('change');
    console.log(event);
    if (event.ratio < 0.4) {
        console.log('We see more than half of the back image');
    }
    if (event.ratio > 0.6) {
        console.log('We see more than half of the front image');
    }

    if (event.ratio <= 0) {
        console.log('We see completely back image');
    }

    if (event.ratio >= 1) {
        console.log('We see completely front image');
    }
});

Changing value

You can change value of visible front part via code :

// important call data('imagesCompare') to get the real object and not the jquery one
var test = $('#myImageCompare').imagesCompare().data('imagesCompare');
test.setValue(0);

Changing value with animation

You can change value of visible front part via code and request an animation :

// important call data('imagesCompare') to get the real object and not the jquery one
var test = $('#myImageCompare').imagesCompare().data('imagesCompare');

// here we pass true in second argument to say we want animation
test.setValue(0, true);

// you can change some settings via the plugin settings (see plugin settings section)
// you can too override duration and easing for one call :
// test.setValue(ratio, animate, duration, easing);

Contribute

Clone the repository, then launch an :

npm install

To lint js and css use :

npm run lint

To build use :

npm run build

To test use :

npm test

(You can open the file src/tests/test.html in your browser too)

Too look available scripts look at the scripts part in the package.json file

Contributors

Credits

External libs and code

Libraries

Code snippets

Images in examples

Images used in example are kindly provided by Céline Skowron, all rights belong to her so you can't use them anywhere without contacting her.

License

Released under the MIT license.

Other libraries on the same subject

jquery-images-compare's People

Contributors

dependabot[bot] avatar greenkeeper[bot] avatar sylvaincombes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jquery-images-compare's Issues

An in-range update of uglify-js is breaking the build 🚨

Version 2.8.0 of uglify-js just got published.

Branch Build failing 🚨
Dependency uglify-js
Current Version 2.7.5
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As uglify-js is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪


Status Details
  • bitHound - Dependencies No failing dependencies. Details

  • bitHound - Code 2 failing files. Details

Commits

The new version differs by 48 commits .

  • 0b0296e v2.8.0
  • 872270b improve error messages (#1506)
  • b1c593a add harmony branch details in README (#1507)
  • 13be50a faster tree transversal (#1462)
  • 16cd5d5 consolidate evaluate & reduce_vars (#1505)
  • 834f9f3 update docs for pure_funcs & drop_console (#1503)
  • cf0951f allow --in-source-map inline (#1490)
  • 852f784 Avoid using exports when undefined (#1471)
  • 229e42c Merge pull request #1485 from alexlamsl/merge-2.8.0
  • 4e49302 enable collapse_vars & reduce_vars by default
  • 1e51586 Support marking a call as pure
  • d48a308 Fix: AST_Accessor missing start / end tokens
  • 26fbeec fix pure_funcs & improve side_effects
  • 8898b8a clean up max_line_len
  • ec64acd introduce unsafe_proto

There are 48 commits in total. See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

[DepShield] (CVSS 7.5) Vulnerability due to usage of set-value:0.4.3

Vulnerabilities

DepShield reports that this application's usage of set-value:0.4.3 results in the following vulnerability(s):


Occurrences

set-value:0.4.3 is a transitive dependency introduced by the following direct dependency(s):

qunit:2.8.0
        └─ findup-sync:2.0.0
              └─ micromatch:3.1.10
                    └─ snapdragon:0.8.2
                          └─ base:0.11.2
                                └─ cache-base:1.0.1
                                      └─ union-value:1.0.0
                                            └─ set-value:0.4.3

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

Fitting images height-wise

Hello.

I'd like to fit te images vertically within the container.

I am loading the slider within an <iframe> and I need the height of <iframe> to be a fixed 600px. I could fit the container by using height: 100%; in the CSS of class .images-compare-container, however, the images just don't fit vertically. I've tried setting their height: 100%; in the class .images-compare-before img, .images-compare-after img and also tried object-fit: cover;, nothing works. The height of the image gets clipped no matter what. I don't mind the extra space along the width of the images (except, they should not get spaced from the center as then the slider would behave in a weird way).

Is this possible and can someone help me with it?

An in-range update of qunitjs is breaking the build 🚨

Version 2.1.1 of qunitjs just got published.

Branch Build failing 🚨
Dependency qunitjs
Current Version 2.1.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As qunitjs is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪


Status Details
  • bitHound - Dependencies No failing dependencies. Details

  • bitHound - Code 2 failing files. Details

Commits

The new version differs by 22 commits (ahead by 22, behind by 1).

  • 677a0b5 2.1.1
  • 9d34d13 Build: Prepare 2.1.1 release, including authors and history update
  • 0c56b4e Assert: Refactor to use ES6 where appropricate
  • e43fbc5 Assert: Refactor Assert to be ES6 class
  • bdd634d All: Remove deprecated 1.x features
  • 265c04f Reporter: move urlparams import from reporter to html
  • 5fd79d6 Assert: Deprecate assert.push
  • c65800b Build: Remove unnecessary QUnit.load call
  • 0e9c683 Core: QUnit.start does not require calliing QUnit.load
  • 8edefa2 HTML Reporter: Add an abort button
  • 365f8d2 Build: Run coverage during CI
  • 294ba43 Build: Re-introduce code coverage for Browser tests
  • 7dfe400 Build: Re-introduce code coverage for Node tests
  • a46fbb5 Build: Replace grunt-contrib-concat with grunt-contrib-copy
  • da70f9d Build: Remove npm prepublish script

There are 22 commits in total. See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of qunitjs is breaking the build 🚨

Version 2.4.0 of qunitjs just got published.

Branch Build failing 🚨
Dependency qunitjs
Current Version 2.3.3
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As qunitjs is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • bitHound - Code 2 failing files. Details
  • bitHound - Dependencies No failing dependencies. Details

Commits

The new version differs by 27 commits ahead by 27, behind by 1.

  • c5b456c 2.4.0
  • 8f7fafd Build: Prepare 2.4.0 release, including authors and history update
  • 6fc5541 Build: Disable max-len ESLint rule for tests
  • 42e8d73 Docs: Document assert.timeout
  • 668d3e3 Tests: Add tests for assert.timeout
  • 445b7b7 Assert: Introduce timeout to set per-test timeout durations
  • ef05ed5 Core: Release objects from memory in equiv
  • 376bbe7 Assert: Fix assert.push deprecation link
  • 35d960b Docs: Fix typo in docs for QUnit.module
  • a3d6cc9 Docs: Document QUnit.module.{only,skip,todo} (#1194)
  • ae158d9 Test: Add tests for QUnit.module.todo()
  • fca1cc4 Core: Implement QUnit.module.todo()
  • 0bf24bc Test: Add tests for QUnit.module.skip()
  • 8801e91 Core: Implement QUnit.module.skip()
  • 6f8ddd3 Core: Fallback to typeof obj in QUnit.objectType.

There are 27 commits in total.

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

[DepShield] (CVSS 7.5) Vulnerability due to usage of debug:2.6.9

Vulnerabilities

DepShield reports that this application's usage of debug:2.6.9 results in the following vulnerability(s):


Occurrences

debug:2.6.9 is a transitive dependency introduced by the following direct dependency(s):

node-qunit-phantomjs:2.1.0
        └─ phantomjs-prebuilt:2.1.16
              └─ extract-zip:1.6.7
                    └─ debug:2.6.9

qunit:2.8.0
        └─ findup-sync:2.0.0
              └─ micromatch:3.1.10
                    └─ extglob:2.0.4
                          └─ expand-brackets:2.1.4
                                └─ debug:2.6.9
                    └─ snapdragon:0.8.2
                          └─ debug:2.6.9

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

An in-range update of jquery is breaking the build 🚨

Version 3.3.1 of jquery was just published.

Branch Build failing 🚨
Dependency jquery
Current Version 3.3.0
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

jquery is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • bitHound - Dependencies 1 failing dependency. Details
  • bitHound - Code No failing files. Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of jquery is breaking the build 🚨

Version 3.2.0 of jquery just got published.

Branch Build failing 🚨
Dependency jquery
Current Version 3.1.1
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As jquery is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this 💪


Status Details
  • bitHound - Code 2 failing files. Details

  • bitHound - Dependencies No failing dependencies. Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

[DepShield] (CVSS 7.5) Vulnerability due to usage of set-value:2.0.0

Vulnerabilities

DepShield reports that this application's usage of set-value:2.0.0 results in the following vulnerability(s):


Occurrences

set-value:2.0.0 is a transitive dependency introduced by the following direct dependency(s):

qunit:2.8.0
        └─ findup-sync:2.0.0
              └─ micromatch:3.1.10
                    └─ snapdragon:0.8.2
                          └─ base:0.11.2
                                └─ cache-base:1.0.1
                                      └─ set-value:2.0.0

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

An in-range update of uglify-js is breaking the build 🚨

Version 3.0.20 of uglify-js just got published.

Branch Build failing 🚨
Dependency uglify-js
Current Version 3.0.19
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As uglify-js is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • bitHound - Code 2 failing files. Details
  • bitHound - Dependencies No failing dependencies. Details

Release Notes v3.0.20

 

Commits

The new version differs by 9 commits.

  • 8b4dcd8 v3.0.20
  • 285401c more tests for #2158 (#2160)
  • 9db4c42 fix cascade & collapse on property access of constants (#2158)
  • 94e5e00 refactor compute_char_frequency() (#2152)
  • dc6bcaa synchronise mangle.properties for minify() & test/compress (#2151)
  • d58b184 refactor Compressor.toplevel (#2149)
  • b3a57ff minimise reduce_vars cloning overhead (#2148)
  • 3d5bc08 fix reduce_vars on this (#2145)
  • 0692435 fix for-in loop parsing (#2144)

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Using png images

When using two png images the left one shows the right one underneath, as the right one is not clipped, how do I prevent this?

An in-range update of node-qunit-phantomjs is breaking the build 🚨

Version 1.6.1 of node-qunit-phantomjs was just published.

Branch Build failing 🚨
Dependency node-qunit-phantomjs
Current Version 1.6.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

node-qunit-phantomjs is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • bitHound - Dependencies 1 failing dependency. Details
  • bitHound - Code No failing files. Details

Commits

The new version differs by 3 commits.

  • 3321b29 v1.6.1
  • f96283b Merge pull request #27 from haiiaaa/master
  • a3b393f Add support for page argument.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

[DepShield] (CVSS 7.5) Vulnerability due to usage of d:1.0.0

Vulnerabilities

DepShield reports that this application's usage of d:1.0.0 results in the following vulnerability(s):


Occurrences

d:1.0.0 is a transitive dependency introduced by the following direct dependency(s):

copy-cli:1.2.1
        └─ cli-color:1.4.0
              └─ d:1.0.0
              └─ es5-ext:0.10.46
                    └─ es6-symbol:3.1.1
                          └─ d:1.0.0
              └─ es6-iterator:2.0.3
                    └─ d:1.0.0
              └─ memoizee:0.4.14
                    └─ d:1.0.0
                    └─ es6-weak-map:2.0.2
                          └─ d:1.0.0
                    └─ event-emitter:0.3.5
                          └─ d:1.0.0

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

[DepShield] (CVSS 7.4) Vulnerability due to usage of phantomjs-prebuilt:2.1.16

Vulnerabilities

DepShield reports that this application's usage of phantomjs-prebuilt:2.1.16 results in the following vulnerability(s):


Occurrences

phantomjs-prebuilt:2.1.16 is a transitive dependency introduced by the following direct dependency(s):

node-qunit-phantomjs:2.1.0
        └─ phantomjs-prebuilt:2.1.16

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

[DepShield] (CVSS 7.5) Vulnerability due to usage of clean-css:3.4.28

Vulnerabilities

DepShield reports that this application's usage of clean-css:3.4.28 results in the following vulnerability(s):


Occurrences

clean-css:3.4.28 is a transitive dependency introduced by the following direct dependency(s):

copy-cli:1.2.1
        └─ clean-css:3.4.28

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

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.