{"id":21873145,"url":"https://github.com/sylvaincombes/jquery-images-compare","last_synced_at":"2026-04-09T00:05:43.204Z","repository":{"id":9084843,"uuid":"60772893","full_name":"sylvaincombes/jquery-images-compare","owner":"sylvaincombes","description":"A jquery plugin for comparing two images","archived":false,"fork":false,"pushed_at":"2022-12-07T17:53:42.000Z","size":1139,"stargazers_count":64,"open_issues_count":15,"forks_count":16,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T01:11:17.825Z","etag":null,"topics":["before-after","compare","compare-images","comparison","image","images","jquery","jquery-images-compare","jquery-plugin"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sylvaincombes.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-09T12:25:35.000Z","updated_at":"2025-01-11T14:41:13.000Z","dependencies_parsed_at":"2023-01-13T15:09:37.538Z","dependency_job_id":null,"html_url":"https://github.com/sylvaincombes/jquery-images-compare","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sylvaincombes%2Fjquery-images-compare","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sylvaincombes%2Fjquery-images-compare/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sylvaincombes%2Fjquery-images-compare/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sylvaincombes%2Fjquery-images-compare/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sylvaincombes","download_url":"https://codeload.github.com/sylvaincombes/jquery-images-compare/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248986312,"owners_count":21194025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["before-after","compare","compare-images","comparison","image","images","jquery","jquery-images-compare","jquery-plugin"],"created_at":"2024-11-28T07:06:39.173Z","updated_at":"2026-04-09T00:05:43.198Z","avatar_url":"https://github.com/sylvaincombes.png","language":"JavaScript","funding_links":[],"categories":["Animation"],"sub_categories":["Images, Maps and Charts"],"readme":"# jQuery Images Compare\n\nA jQuery plugin for comparing two images\n\nPrefer a no-dependency version? A vanilla alternative will be available as `vanilla-images-compare` and should be preferred when you do not need jQuery.\n\n![jquery images compare preview](https://raw.githubusercontent.com/sylvaincombes/jquery-images-compare/master/preview.gif)\n\n[![CI](https://github.com/sylvaincombes/jquery-images-compare/actions/workflows/ci.yml/badge.svg)](https://github.com/sylvaincombes/jquery-images-compare/actions/workflows/ci.yml) [![npm](https://img.shields.io/npm/v/jquery-images-compare.svg?style=flat-square)](https://www.npmjs.com/package/jquery-images-compare) [![npm downloads](https://img.shields.io/npm/dm/jquery-images-compare.svg?style=flat-square)](https://www.npmjs.com/package/jquery-images-compare) [![license](https://img.shields.io/github/license/sylvaincombes/jquery-images-compare.svg?style=flat-square)](https://raw.githubusercontent.com/sylvaincombes/jquery-images-compare/master/LICENSE.md)\n\n## Features\n\n- compatibility : Chrome 80+, Edge 80+, Firefox 74+, Safari 13.1+ (no IE)\n\n- Dependency footprint: jQuery only.\n\n- Effort to put appearance via css (easier to skin / override)\n\n- Touch friendly, mouse drag (Pointer Events)\n\n- Responsive\n\n- You can listen to change event to add some of your logic\n\n- You can change the value from external code\n\n- Animation option when changing the value\n\n- Optional alternative interaction modes : drag by default (the recommended one), click and mousemove (warning desktop friendly only for this settings)\n\n- Size : ~2k of js and ~0.5k of css (minified and gzipped)\n\n\u003e NB : This library only does horizontal slide\n\n## Quick start\n\n### Via CDN\n\nThe easiest way to get started — no installation required. Both [jsDelivr](https://www.jsdelivr.com/) and [unpkg](https://unpkg.com/) serve the package directly from npm.\n\n**jsDelivr:**\n\n```html\n\u003clink\n    rel=\"stylesheet\"\n    href=\"https://cdn.jsdelivr.net/npm/jquery-images-compare@4.0.0/build/images-compare.min.css\"\n/\u003e\n```\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/jquery-images-compare@4.0.0/build/jquery.images-compare.min.js\"\u003e\u003c/script\u003e\n```\n\n**unpkg:**\n\n```html\n\u003clink\n    rel=\"stylesheet\"\n    href=\"https://unpkg.com/jquery-images-compare@4.0.0/build/images-compare.min.css\"\n/\u003e\n```\n\n```html\n\u003cscript src=\"https://unpkg.com/jquery-images-compare@4.0.0/build/jquery.images-compare.min.js\"\u003e\u003c/script\u003e\n```\n\n### Via local files\n\nIn your head section, include the css (a minified version is also provided) :\n\n```html\n\u003clink rel=\"stylesheet\" href=\"images-compare.css\" /\u003e\n```\n\nInclude the required javascript, before the body closing tag :\n\n```html\n\u003cscript\n    type=\"text/javascript\"\n    src=\"https://code.jquery.com/jquery-4.0.0.min.js\"\n    integrity=\"sha256-OaVG6prZf4v69dPg6PhVattBXkcOWQB62pdZ3ORyrao=\"\n    crossorigin=\"anonymous\"\n\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\" src=\"jquery.images-compare.min.js\"\u003e\u003c/script\u003e\n```\n\nNote: use the full jQuery build (not the slim build). The slim build excludes the Ajax and effects modules, and this plugin relies on jQuery effects for animation.\n\nNote: jQuery 4 is the supported baseline. Older jQuery versions are not officially supported; use jQuery Migrate when upgrading from jQuery 3.x.\n\nSetup your html (minimal example) :\n\n```html\n\u003c!-- Main div container --\u003e\n\u003cdiv id=\"myImageCompare\"\u003e\n    \u003c!-- The first div will be the front element, to prevent FOUC add a style=\"display: none;\" --\u003e\n    \u003cdiv style=\"display: none;\"\u003e\n        \u003cimg src=\"assets/img/before.jpg\" alt=\"Before\" /\u003e\n    \u003c/div\u003e\n    \u003c!-- This div will be the back element --\u003e\n    \u003cdiv\u003e\n        \u003cimg src=\"assets/img/after.jpg\" alt=\"After\" /\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n```\n\nCall the plugin :\n\n```js\n$(\"#myImageCompare\").imagesCompare();\n```\n\n## Documentation\n\n### Install via npm\n\n```sh\nnpm install jquery-images-compare\n```\n\n### Tooling (optional)\n\nThis repo includes a `mise.toml` for pinning Bun. If you use `mise`, run:\n\n```sh\nmise install\n```\n\nYou can also install Bun directly if you do not use `mise`.\n\n### Git Hooks (optional)\n\nTo enable the pre-commit lint hook:\n\n```sh\ngit config core.hooksPath .githooks\n```\n\n### Plugin settings\n\nYou can change plugin settings by passing an option object, example :\n\n```js\n$(\"#myImageCompare\").imagesCompare({\n    initVisibleRatio: 0.2,\n    interactionMode: \"mousemove\",\n    addSeparator: false,\n    addDragHandle: false,\n    animationDuration: 450,\n    animationEasing: \"linear\",\n    precision: 2,\n});\n```\n\nList of available options :\n\n| key               | Description                                                                              | Default value                       |\n| ----------------- | ---------------------------------------------------------------------------------------- | ----------------------------------- |\n| initVisibleRatio  | Visible ratio of front element on init, float value between 0 and 1                      | 0.5 (front element is half visible) |\n| interactionMode   | The interaction mode to use, valid values are \"drag\" (recommended), \"mousemove\", \"click\" | \"drag\"                              |\n| addSeparator      | Add a html separator element ? (thin vertical blank line) - _boolean_                    | true                                |\n| addDragHandle     | Add a html \"drag handle\" element ? - _boolean_                                           | true                                |\n| animationDuration | default animation duration in ms                                                         | 400                                 |\n| animationEasing   | default animation easing to use (\"linear\", \"swing\")                                      | \"swing\"                             |\n| precision         | Ratio precision, numbers after the decimal point                                         | 4                                   |\n\n### Changing appearance\n\nThe styling is done via css, to let you change it by css overrides.\n\n#### Css classes\n\nBasic list of main css classes, for full details please have a look at the css file.\n\n| Selector                                                 | Description                          |\n| -------------------------------------------------------- | ------------------------------------ |\n| \\.images-compare-container                               | Container of the elements            |\n| \\.images-compare-before                                  | Front element                        |\n| \\.images-compare-after                                   | Back element                         |\n| \\.images-compare-separator                               | Separator (thin vertical blank line) |\n| \\.images-compare-handle                                  | Drag handle (circle)                 |\n| \\.images-compare-left-arrow, .images-compare-right-arrow | Drag handle arrows                   |\n| \\.images-compare-label                                   | Label class element                  |\n\n#### Markup example with labels\n\nYou can add labels, add the class _images-compare-label_ to your elements.\n\nA default styling will be applied, you can override css rules to customize to your needs.\n\n```html\n\u003c!-- Main div container --\u003e\n\u003cdiv id=\"myImageCompare\"\u003e\n    \u003c!-- The first div will be the front element, to prevent FOUC add a style=\"display: none;\" --\u003e\n    \u003cdiv style=\"display: none;\"\u003e\n        \u003cspan class=\"images-compare-label\"\u003eBefore\u003c/span\u003e\n        \u003cimg src=\"assets/img/before.jpg\" alt=\"Before\" /\u003e\n    \u003c/div\u003e\n    \u003c!-- This div will be the back element --\u003e\n    \u003cdiv\u003e\n        \u003cspan class=\"images-compare-label\"\u003eAfter\u003c/span\u003e\n        \u003cimg src=\"assets/img/after.jpg\" alt=\"After\" /\u003e\n    \u003c/div\u003e\n\u003c/div\u003e\n```\n\n### Events\n\nList of events the plugin triggers :\n\n| Event name                | Description                                                                  |\n| ------------------------- | ---------------------------------------------------------------------------- |\n| imagesCompare:initialised | This event is fired when init is done                                        |\n| imagesCompare:changed     | This event is fired when the value of visible front element is changed       |\n| imagesCompare:resized     | This event is fired when a resize window event has been received and treated |\n\n#### Example listening to change event\n\n```js\n// important call data('imagesCompare') to get the real object and not the jquery one\nvar test = $(\"#myImageCompare\").imagesCompare().data(\"imagesCompare\");\n\ntest.on(\"imagesCompare:changed\", function (event) {\n    console.log(\"change\");\n    console.log(event);\n    if (event.ratio \u003c 0.4) {\n        console.log(\"We see more than half of the back image\");\n    }\n    if (event.ratio \u003e 0.6) {\n        console.log(\"We see more than half of the front image\");\n    }\n\n    if (event.ratio \u003c= 0) {\n        console.log(\"We see completely back image\");\n    }\n\n    if (event.ratio \u003e= 1) {\n        console.log(\"We see completely front image\");\n    }\n});\n```\n\n### Changing value\n\nYou can change value of visible front part via code :\n\n```javascript\n// important call data('imagesCompare') to get the real object and not the jquery one\nvar test = $(\"#myImageCompare\").imagesCompare().data(\"imagesCompare\");\ntest.setValue(0);\n```\n\n### Changing value with animation\n\nYou can change value of visible front part via code and request an animation :\n\n```js\n// important call data('imagesCompare') to get the real object and not the jquery one\nvar test = $(\"#myImageCompare\").imagesCompare().data(\"imagesCompare\");\n\n// here we pass true in second argument to say we want animation\ntest.setValue(0, true);\n\n// you can change some settings via the plugin settings (see plugin settings section)\n// you can too override duration and easing for one call :\n// test.setValue(ratio, animate, duration, easing);\n```\n\n### Contribute\n\nClone the repository, then launch an :\n\n```sh\nbun install\n```\n\nTo lint js and css use :\n\n```sh\nbun run lint\n```\n\nTo build use :\n\n```sh\nbun run build\n```\n\nTo test use :\n\n```sh\nbun run test\nbun run test:serve\n```\n\n(Then open `http://localhost:41721/src/tests/test.html` in a browser.)\n\nOn macOS you can also run:\n\n```sh\nbun run test:open\n```\n\nTo open the example page:\n\n```sh\nbun run example:serve\n```\n\n```sh\nbun run example:open\n```\n\n_Too look available scripts look at the scripts part in the package.json file_\n\n## Contributors\n\n- [@sylvaincombes](https://github.com/sylvaincombes) (Maintainer)\n- [@drenawak](https://github.com/drenawak)\n- [Céline Skowron](https://celine-skowron.fr)\n- [Iván Pérez](https://github.com/Ivan-Perez)\n\n## Credits\n\n### External libs and code\n\n#### Libraries\n\n- [jQuery](https://jquery.com)\n\n#### Code snippets\n\n- Drag Handle look and feel taken from [zurb twentytwenty](https://github.com/zurb/twentytwenty)\n\n## Browser Support\n\nThis plugin uses Pointer Events for drag interactions and targets modern evergreen browsers:\n\n- Chrome 55+\n- Edge 12+\n- Firefox 59+\n- Safari 13+\n\nOlder browsers (including Internet Explorer) are not supported.\n\n### jQuery 4 Support Policy\n\nBecause this project uses jQuery 4, browser support follows the jQuery 4 policy:\n\n- Chrome/Edge/Firefox/Safari: current and current-1\n- Opera: current\n- iOS Safari: current, current-1, current-2\n- Android Chrome: current and current-1\n- Internet Explorer: 11 only\n\n### Images in examples\n\nImages used in example are kindly provided by [Céline Skowron](https://celine-skowron.fr), all rights belong to her so you can't use them anywhere without contacting her.\n\n## License\n\nReleased under the MIT license.\n\n## Other libraries on the same subject\n\n- [zurb twentytwenty](https://github.com/zurb/twentytwenty)\n- [jquery-beforeafter-plugin](http://www.catchmyfame.com/catchmyfame-jquery-plugins/jquery-beforeafter-plugin/)\n- [juxtapose](https://juxtapose.knightlab.com/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsylvaincombes%2Fjquery-images-compare","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsylvaincombes%2Fjquery-images-compare","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsylvaincombes%2Fjquery-images-compare/lists"}