Giter Club home page Giter Club logo

twentytwenty's Introduction

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.

twentytwenty's People

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  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  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  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

twentytwenty's Issues

jquery.event.props undefined

Above all thank you for your plugin, very useful to present work.

I'm encountering an error with jquery.event.move using jquery 3.0.0 but not 2.2.3.
At page render I've got this error :
Uncaught TypeError: Cannot read property 'indexOf' of undefined
on jquery.event.move.js:580

Do you know where does it come ?

Limit max right and max left [SOLVED]

how can i limit for not cut the circle handle,

i try with overflow visible but handle becomes visible with top and button bars, overflow-x:visible not works.

NPM package

Why don't pack for npm? or another pack manager, it's not best practice to clone repo and import js file manually :(

Causes Touch Event Problems on Mobile

Works great but when visiting the site I implemented it on a mobile device, the touch events seem to be messed up for the entire page. Clicking links of any kind take two taps as opposed to one and I was able to determine that the problem area is jquery.event.move.js. When I remove that file, the touch events for the entire page work well, my navigation toggle is quick and responsive, all links take one click to activate, etc. But upon placing the file jquery.event.move.js back in again, all of my touch targets get messed up again and require 2 quick taps to register.

Chage the position of comparation

Hi! I made a project and used this plugin. But i want to change the position of the anchor of comparision.
How can i make this, because i want that the stayed on the center of image? Then we can drag to the sides.

Handle gets stuck after faster move.

Hi,

I found an issue:

when you want to move handle to the left or right a bit faster it gets stuck somewhere on the way. Especially if your mouse ends outside of the twentytwenty container.
Issue can be recreated even on the plugin homepage (http://zurb.com/playground/twentytwenty).
This issue is present in all major browsers, tested latest Chrome, Firefox, Opera and IEs.

Thanks :)

add version number

hi, recently we want to your lib on https://cdnjs.com, i think maybe this lib only has one version, can we regards it as v1.0.0 on cdnjs? or if you have free time, we hope you can add git tag for this version, just in case if there will be a later version, our git auto-update config can add it automatically.
thank you very much!

cdnjs/cdnjs#7125

Bower

Be nice to have this on Bower.

'Before' Image offset doesn't show at startup

Hi Folks

I got an issue I just experienced on the website I'm working on. I'm using Twentytwenty with an offset set at 0.2. When the twentytwenty container is shown, I can only see the second image ('After' in default configuration, 'Before' on mine but whatever) while the handle is correctly set à 20% of the width. (Screenshot)

Whenever I click on or drag the handle, everything goes back to normal and the plugin works.

Any ideas ?
Thanks
sans-titre-1

Safari 6.0.5 [Mac] handle sometimes jumps to the left

Hi guys,

firstly, thank you for your hard work and beautiful plugin.
But I found an issue today. On mac, safari 6.0.5 while sliding, the handle sometimes suddenly jumps to the left. And therefore it will show "Before" picture completely. After moving it a bit more it jumps back to the intended position.
Issue can be reconstructed even on plugin home page.

http://zurb.com/playground/twentytwenty

Thanks for fixing it, I would love to use it on my latest project.

Johnny

Resized container in Fancybox on mobile

Hi folks!

I have another issue with Twentytwenty plugin within fancybox. The website I work on is using simple responsive @media queries and while the fancybox on standard images works fine, the ones with twentytwenty on them doesn't fit the device screen and are resized to full size.

Have a look on screenshots below :)

Thank for your though on this 👍
phone 01
phone 02

Custom Before / After Labels are being overwritten by CSS

Since it's possible to have custom options, like:

$(".twentytwenty-container").twentytwenty({
	before_label: 'Cover',
	after_label: 'Article'
});

I'm not sure why you have this in the default CSS:

.twentytwenty-before-label::before {
    content: "Before";
}
.twentytwenty-after-label::before {
    content: "After";
}

Because it overrides the set labels in options... just curious if this is a bug or leftover from old code?

Vertical Slider issue on IOS devices

The vertical slider doesn't works well in IOS devices. When we touch and scroll it actually scrolls the page and not the slider.

Please let me know if there is a fix for that?

Thanks,
Munir

No divs displayed when used in any carousel or slider

I have multiple instances of TwentyTwenty, that at the moment, are stacked ontop of each other, with thumbnails underneath. When each of the thumbnail is clicked, the relevant 20/20 slider is displayed by a combination of CSS display/hide, and data-image to link up the slider to the thumbnail.

However, I would like to put the 20/20 sliders into a carousel, and be able to cycle through them with left and right arrows. The problem is, any carousel I try to put these into (Bootstrap for example), requires a class of active to move around to a certain slider. Some of the sliders have no height, and it just looks messy.

There are loads of others who are saying about multiple sliders, having zero height properties, and so don't show.

Is there a tried and tested method of using multiple 20/20 sliders within a carousel?

Does not work on Rails

I've implemented on a rails project and it simply does not work, height of the container is just set to 0px.
Is there a fix for this or can anyone recommend a similar plugin which is rails friendly?

Show Before and After Label

Is there a way to set the 'Before' and 'After' labels to always appear, just in case the use doesn't 'get it'?
Not sure what I'd change in the css

Random issue with -webkit-animation-duration css

I have a pretty random situation with a site I'm trying to create, that includes twenty twenty and a css animation; they seem to conflict in a manor.

I have made a fiddle here: http://jsfiddle.net/wta8B/

In a nutshell, if you remove the -webkit-animation-duration css from the .oil-can animation, then twenty twenty works as it should. If the css line is there, the twenty twenty app doesn't display both images, just the one.

Look forward to your response, it is extremely random.

Not touch friendly on tablets nor phones when into fancybox

Everything seemed to be perfect as soon as I was getting to the end of the development of this site http://www.destizons.com but unfortunately when I checked the twenty twenty on my Ipad I realized that I cant use it normally as I do on my computer. I 'am not able to drag the images. You can check it out on this site http://www.destizons.com/nos-services-plus/ by clicking on "Relooking": If anybody knows what I've done wrongly or can give me a solution I would be thankful.

AngularJS minified not working

Hello,

I'm using this plugin within my angular application and it works just fine.
However, when I build my app using grunt all of my javascript gets minified and this plugin stops working completely.

Container would take the whole width of the page despite of the image width

The Images and script would worked fine but the (before/after) overlay would take the whole width of the page and the actual images would be align to left. Ended up editing the script to add line in the "adjustContainer" function and it keeps the responsiveness resolved in #15
container.css("max-width", offset.w);

Also added margin:auto; to twentytwenty-container class

Initial slider position bug

I've created a page that has seven containers, each with their own image comparison module. I've initialized the plugin using a class name, however I'm getting very inconsistent performance about where the slider is positioned on the initial load.

Sometimes the slider starts at the default center position, but other times it will start all the way to the left. There isn't any pattern to the bug since multiple page refreshes always yield different results.

Is there a better, or more efficient way to load multiple sliders without having this bug appear?

Scrollbar bug when page content height close to window height

When the page content is just less than the viewable window height, using twentytwenty causes the page to increase in size, causing scrollbars. This reduces the image width, meaning that the page height is reduced and scrollbars disappear. The effect is that scrollbars blink in and out of existence.

Bug in action:
twenty-twenty-bug

Is it responsive?

Hi,

Great work on the plugin.

I re-read your description few times, and it looks like this implementation should be responsive. But this is not the case?

In my scenario, I used width 100% on wrapper, but image never gets enlarged or resized down. I see in css height is fixed.

What would you suggest to do in this situation?

Slow drag

Hey,

I'm having a issue, when I drag the slider it's super slow compare to the demo. I tried the plugin on a separated project it's working fine. I don't know why I'm having this problem. I'm using jQuery 1.10.1 like the demo and also event.move.js.

Any thought ?

Thanks.

Is there a way to re-run plugin on same element? to recalculate width? height?

Running this: $(your_image_container).twentytwenty(); on the element which had previously twentytwenty active adds unnesseary containers. Basically on each run it recreates divs needed for the plugin, creating a big mess of nested containers.

This behaviour is very disruptive for any move to make plugin responsive. Since re-running it on element on-resize creates mess of elements.

Move handle on mousemove

The WebFlow team has implemented a custom desktop-only comparison slider that is pretty hot:

https://webflow.com/#features

It would be sweet to bring this functionality into TwentyTwenty as an option. Specifically:

  1. On mousemove event the handle should move to match where the mouse is located
  2. On mouseleave event the handle should animate back to its starting position

Strange touch event on twentytwenty-handle

I have been looking through the twentytwenty css and js code and I still can't understand where a particular behavior is coming from.

Anyhow, I have tweaked this plugin so that it does not show the handler in the middle or the arrows - just the separation line between the images. This when I can see a strange behavior happening...

When checking it out on a smartphone, I touch on the center of the image - a little grey translucent box flashes up on the screen (centered both horizontally and vertically). For the life of me I cannot style this (with css) or get rid of it. Of course I can css style the handler with a specific background color but it the 'shadow flash' affect still keeps happening.

Can anyone tell me how to control this behaviour? It almost appears to be some native webkit behaviour or something.

Doesn't work inside modal windows

What is required for these to work in terms of divs around them?

This plugin will not work when placed inside a modal window... which is a big problem for me. I'm using fancybox, and need to find a way of displaying these sliders to take up the full width of the modal window.

Not displaying at load but pops up when resizing window

Hi, I'm using twenty twenty but sometimes the images dont show up at all. If I resize the window it pops up and after that it displays correctly. Is there anything I can to do fix this?
I've got it inside a div class with width: 100% !important; but that didnt solve the issue.

Anyone got any ideas on how to solve this?

Thanks

Edit: Adding a 1px border seems to have partially solved the issue, if anyone knows something better it would be nice.

Edit 2: Nvm, adding a 1px border doesn't work all the time. It randomly chooses to not work. It works in in IE and FF but not chrome.

Problem with lightbox combination

Hey,
this is not really an issue with your plugin itself. The plugin alone works pretty good for me. Thanks a lot by the way :)
I struggle with the combination of the lightbox plugin: "Fancybox".
So basicly not your problem but i thought maybe have a fast idea how i can solve my problem :)

My goal ist to open a lightbox window and have the ability to wipe the images inside with your before/after script.
As you can see here: http://robinjuenkersfeld.de/test_2.php (click on the image) mostly it does what it should but the layout gets broken inside the lightbox. The "before & after tags" are in the top left corner and the wipe line disappears.

(I disabled the "auto height" css command for "img" in the foundation.css. Otherwise the height seems to conflict with the lightbox "display none" and the twentytwenty div gets a 0px height so you see nothing.)

So the whole problem seems to go along with the "display: none" command which is requiered for hiding the div for the lightbox effect. I have tried a lot and don't know any further.
Funny thing: if you click fast enough before the page ist fully loaded, everything looks perfect but still breaks after closing and opening again.

Is there a chance to combine those plugins? If necessary i would use another lightbox plugin as well.

Thanks a lot for your time!
Rob

Moving slider through JS

Hello,

I've been wanting to move the slider through code (dynamically setup default_offset_pct). However, there doesn't seem to be a way to do so. Does anyone happen to have a recommendation to do so?

Better Instructions

Hi, I have watched numerous clients fumble around the idea of how to work the before and after. I saw a ton of clicking on the word “before” or “after” no one could seem to grasp the click and drag. I added a parenthesis below my click and drags that says (click and drag to reveal the before and after) still nothing, Is there a way you guys can give instruction when you hover? Or have the before and after words on the the hover be an action, like, move the slider for them?

TinyMCE Implementation

Hi, thank you for nice plugin.

I have a two question:

  1. Is that plugin compatible with Bootstrap 3.x?
  2. How about TinyMCE button for insert TwentyTwenty block into editor?

Thank you.

CSS clip for afterImg

When using transparent .PNG or .SVG for the before and after images, you can always see the afterImg below, while the beforeImg gets a clipping rect mask applied on the fly. It would be great, if the afterImg could also be masked inversely while using the slider.

Animating the slider

Is it possible to animate the slider? It would be great for my site if the slider automatically slowly moved to the left and thus slowly revealed the 'after' image.

TwentyTwenty has height issues when used with Owl Carousel

This has always been a bit of an on-going issue since I started using these two items together. I know that I definitely want to use them both, and there must be a way to do it, as I've seen it used on other sites.

Anyway, I've tried using the 20/20 on it's own, and it seems to work fine when static. I've also used Owl Carousel 2 on it's own with static images, and that seems to work fine too.

But when I try to combine them, so I have multiple instances of 20/20 as 'slides' in Owl Carousel, there is an issue regarding the height of the 20/20 container, when resizing the windows.

This leads to issues when rotating mobile devices, and changing browser sizes. Usually, it sometimes gets fixed by resizing and after letting go of the mouse buttons, it may change. But sometimes it does not.

I've tried using the window.resize in the past, but that doesn't seem to make any difference.

A good example of this can be found at https://www.bellavou.co.uk/face/facelift/ - Try resizing the browser window when viewing the 20/20 slider, and after a while, you'll start to see gaps making the slide container appear huge, and not resizing with the browser.

I'm not sure what I can do, but I'm open to all suggestions and all help is appreciated! Sorry for the wordy issue...

z-index overlaps other components on the page

This in particular happens with WordPress's newest default theme:

image

The z-index on the img and overlay elements is higher than the z-index of the theme's fixed nav (4).

I'm not sure of the fix here, other than lower the z-indexes on TwentyTwenty.

Problems with bootstrap tabs and twentytwenty plugin

Hi, I'm building a website with bootstrap and twentytwenty plugin. I have a page that use bootstrap tabs to compare two photos to many services, but when a I put the twentytwenty plugin on many tabs, my images don't appear. Inspecting the element, the images height is 0. It's a problem with the plugin? Sorry about my english.

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.