• Stars
    star
    1,264
  • Rank 37,217 (Top 0.8 %)
  • Language
    CSS
  • License
    ISC License
  • Created over 11 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

jQuery Plugin to Compare Images

Basic usage

Include the javascript and css files.

<script src="js/jquery-3.2.1.min.js" type="text/javascript"></script>
<script src="js/jquery.event.move.js" type="text/javascript"></script>
<script src="js/jquery.twentytwenty.js" type="text/javascript"></script>
<link rel="stylesheet" href="css/twentytwenty.css" type="text/css" media="screen" />

You might need to change the paths to match your setup.

After including the files you are ready to create a container that holds two images:

<div id="container1">
 <!-- The before image is first -->
 <img src="http://placehold.it/400x200&amp;text=1" />
 <!-- The after image is last -->
 <img src="http://placehold.it/400x200&amp;text=2" />
</div>

Now initialize the plugin on the window load:

$(function(){
  $("#container1").twentytwenty();
});

Options

$(function(){
  $(".twentytwenty-container").twentytwenty({
    default_offset_pct: 0.7, // How much of the before image is visible when the page loads
    orientation: 'vertical', // Orientation of the before and after images ('horizontal' or 'vertical')
    before_label: 'January 2017', // Set a custom before label
    after_label: 'March 2017', // Set a custom after label
    no_overlay: true, //Do not show the overlay with before and after
    move_slider_on_hover: true, // Move slider on mouse hover?
    move_with_handle_only: true, // Allow a user to swipe anywhere on the image to control slider movement. 
    click_to_move: false // Allow a user to click (or tap) anywhere on the image to move the slider to that location.
  });
});

Prevent FOUC

If you want to avoid a FOUC you can append the twentytwenty-container class to your container like so:

<div id="container1" class="twentytwenty-container">
 <!-- The before image is first -->
 <img src="http://placehold.it/400x200&amp;text=1" />
 <!-- The after image is last -->
 <img src="http://placehold.it/400x200&amp;text=2" />
</div>

Multiple instances

If you want to use multiple instances of this plugin on a single page you can target the container class:

$(function(){
  $(".twentytwenty-container").twentytwenty();
});

Build with SCSS

You can use SCSS to customise the TwentyTwenty styles. All you need to do is make sure you have NPM and Grunt installed. Then, clone the repository and run "npm install" to install all the required Grunt modules. Run "grunt develop" to compile your CSS file (the Gruntfile is also configured to watch for changes):

git clone [email protected]:zurb/twentytwenty.git
npm install
grunt develop

All default Sass variables can be found in scss/twentytwenty.scss.

Support

  • IE8+
  • Firefox (latest)
  • Chrome
  • Safari
  • Android
  • iOS (iPhone, iPad)

Dependencies

MIT Open Source License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

tribute

ES6 Native @mentions
JavaScript
2,032
star
2

foundation-apps

The first front-end framework created for developing fully responsive web apps.
CSS
1,580
star
3

joyride

jQuery feature tour plugin.
JavaScript
1,420
star
4

reveal

JavaScript
676
star
5

foundation-5-sublime-snippets

ZURB Foundation 5 Sublime Text 2 Snippets
492
star
6

orbit

JavaScript
457
star
7

responsive-tables

Tables that work responsively on small devices.
CSS
431
star
8

foundation-icons

CSS
427
star
9

pizza

Better pie, donut, line, and bar graphs.
JavaScript
413
star
10

flickrbomb

flickrBomb provides an easy way for you to fill your prototypes with relevant content, and not just those dull gray placeholder images.
JavaScript
270
star
11

foundation-icon-fonts

Foundation Icon Fonts
HTML
111
star
12

html5_video_voting

78
star
13

foundation-apps-template

Our starter template for Foundation for Apps projects. Powered by Angular, Sass, and Gulp.
CSS
74
star
14

foundation-layouts

Sample layouts for the Zurb Foundation Framework
JavaScript
54
star
15

reactive-listener

JavaScript
42
star
16

fastclick

JavaScript
34
star
17

advanced-foundation-course

Content for Advance Foundation Course
CSS
33
star
18

wrangle

JavaScript
32
star
19

foundation-course

Material for Foundation Course JavaScript
CSS
30
star
20

foundation-templates-layer

Templates that are integrated into Foundation's templates layer downloads.
JavaScript
24
star
21

css-flip-book

CSS
24
star
22

ZURB-code-standards

Code standards for ZURB's family of products and client deliverables.
19
star
23

foundation-migrate

Foundation migration plugin: http://foundation.zurb.com/docs/upgrading.html
JavaScript
16
star
24

foundation-sites-6

[ARCHIVED] Version 6.0 of Foundation for Sites (Public Beta).
HTML
14
star
25

inky-cli

Command-line interface for the Inky templating language.
JavaScript
13
star
26

angular-tribute

Angular directive for Tribute.js
JavaScript
10
star
27

front-router

Generate AngularJS states from Front Matter in state templates. Used by Foundation for Apps.
JavaScript
8
star
28

ARCHIVED-giving-tree-wordpress

7
star
29

notable-cli

Upload to Notable from the command-line
Go
7
star
30

media-query-examples

Media Query Examples
CSS
7
star
31

foundation-demo

This is a demo repository for meetups and conferences to show the process of building a simple page using Foundation.
CSS
7
star
32

foundation-inline-svg

JavaScript
7
star
33

tribute-rb

Tribute.js @mentions for the Rails Asset Pipeline
Ruby
7
star
34

foundation-compass-stack

This is a stack for developing your website using Foundation, with Assemble for templates and Compass for Sass compilation.
CSS
7
star
35

siphon-media-query

Extract media query-specific rules from CSS.
JavaScript
6
star
36

sample-scss-project

Sample Sass Project
5
star
37

F5-accessibility-audit

5
star
38

ARCHIVED-giving-tree-static

Giving Tree static site skeleton
PHP
5
star
39

topbar

topbar
CSS
4
star
40

inky-rails-talk

Live code/demo for inky-rb rails integration
Ruby
4
star
41

cardpack

A collection of Badass Foundation Flex Cards
HTML
3
star
42

zurb-template

ZURB's Client Project Template
JavaScript
3
star
43

yetinews

Tutorial project for Foundation for Apps protoype
CSS
2
star
44

10-minute-responsive-email

Code from the Foundation meetup - Foundation for Emails
JavaScript
2
star
45

wrangle-demo

Demo of wrangle.
JavaScript
2
star
46

client-template

Template for client projects, using Assemble.
CSS
1
star
47

zurb-talk-demos

CSS
1
star
48

building-blocks-ARCHIVED

HTML
1
star
49

Helio-Blog

PHP
1
star