Code Monkey home page Code Monkey logo

juxtapose's Introduction

JuxtaposeJS

[JuxtaposeJS][https://juxtapose.knightlab.com] is a simple, open source tool for creating before/after image sliders. Just provide two image URLs and Juxtapose will do the rest of the work for you. Below are instructions for implementing Juxtapose with HTML and Javascript but we also have a tool that lets you make a slider without needing to know any code.

If you want to contribute to Juxtapose, check out the DEVELOPERS.md file for installation instructions. Fork the project, create a new branch with your features, and submit a pull request. Thanks for your help!

Contents

Installation

The easiest way to create a Juxtapose slider is to go to to [https://juxtapose.knightlab.com][1] and use the tool to generate an embedable code snippet that you can use on any website. There are a number of other ways to install Juxtapose on your website.

CDN — Juxtapose is available on the Knight Lab CDN. Just add this code to the <head> of your HTML page:

<script src="https://cdn.knightlab.com/libs/juxtapose/latest/js/juxtapose.min.js"></script>
<link rel="stylesheet" href="https://cdn.knightlab.com/libs/juxtapose/latest/css/juxtapose.css">

Package Managers — Juxtapose is available on both the npm and Bower package registries. The following commands will, respectively, save Juxtapose to your package.json and bower.json requirements files.

npm install --save juxtaposejs
bower install --save juxtapose

There is also a Meteor package available.

Create a Juxtapose Slider

Create an iFrame

The easiest way to create a Juxtapose slider is to go to to [https://juxtapose.knightlab.com][1] and use the tool to generate an embedable code snippet that you can use on any website. The tool is easy to use and requires no coding knowledge whatsoever. If you want to use JuxtaposeJS without using the embed generator, keep reading to learn about different implementation methods.

HTML Implementation

The easiest way to implement the image slider is to add this code to your markup:

<div class="juxtapose">
    <img src="https://example.com/firstimage.jpg" />
    <img src="https://example.com/secondimage.jpg" />
</div>
<script src="https://cdn.knightlab.com/libs/juxtapose/latest/js/juxtapose.min.js"></script>
<link rel="stylesheet" href="https://cdn.knightlab.com/libs/juxtapose/latest/css/juxtapose.css">

Each img can also take additional attributes like so:

<img src="https://example.com/image.jpg" data-label="2009" data-credit="Alex Duner/Northwestern Knight Lab" />

If each image has an data-label attribute defined, the slider will display a label on each image. If each image has a data-credit attribute defined, the slider will display a credit for each image.

The slider wrapper can also take some additional attributes as well to specify a few options:

<div id="juxtapose-wrapper" class="juxtapose" data-startingposition="35%" data-showlabels="false" data-showcredits="false" data-animate="false">...</div>

Specifying a starting position with data-startingposition lets you focus the users attention on the part of the image where the change is most noticeable. To toggle the visibility of the labels and the credits respectively, set data-showlabels and data-showcredits to false. And to disable the animation, set data-animate to false.

If you are using Juxtapose in an existing responsive iFrame solution like pym.js and don't want to use Juxtapose's built in (but faily opinionated) responsive iFrame solution, you can set data-makeresponsive to false.

Javascript Implementation

The JXSlider class takes three arguments. First, is the string of the ID of the element you want to turn into a slider. Second is an array of two objects. Each object must have src defined and can optionally define a label and a credit. The third argument lets you set additional options for the image slider.

<div id="foo"></div>
<script>
slider = new juxtapose.JXSlider('#foo',
    [
        {
            src: 'https://example.com/firstimage.jpg',
            label: '2009',
            credit: 'Image Credit'
        },
        {
            src: 'https://example.com/secondimage.jpg',
            label: '2014',
            credit: "Image Credit"
        }
    ],
    {
        animate: true,
        showLabels: true,
        showCredits: true,
        startingPosition: "50%",
        makeResponsive: true
    });
</script>

Modifications and Custom Behavior

CSS

You can customize how JuxtaposeJS looks by modifying its CSS. For instructions, click here.

JavaScript

The JXSlider class contains a few methods you can use to modify your sliders.

If you instantiated your sliders with the HTML method but still want to access one of your sliders programmatically, JuxtaposeJS creates an array of the JXSliders on your page that you can access with juxtapose.sliders.

JXSlider.updateSlider(percentage, animate);

Percentage indicates where you want to set the handle relative to the left side of the slider. If you set animate to true, the handle will animate to the new location; if animate is set to false, the handle will not.

Security Information

As part of rendering a juxtapose instance, this library renders a "credit" as HTML. Juxtapose passes this string directly through from the data-credit attribute, or from the credit property of the configuration object for either of the images.

In the strictest sense, this exposes an XSS vulnerability; however, we believe that for JuxtaposeJS to exist as a tool in a toolkit, it is both responsible and optimal to leave any HTML sanitizing as the responsibility of integrators, who may have their own ideas about what is appropriate. Therefore, take note: if you are providing a service which helps people to create juxtapose instances, you should take appropriate responsibility for preventing the injection of malicious code.

juxtapose's People

Contributors

55sketch avatar blackice2999 avatar duner avatar hbillings avatar joegermuska avatar joshuadoshua avatar kklai avatar mazhang2718 avatar pallxk avatar radiocontrolled avatar scott2b avatar sehmon avatar shengwu avatar sudheesh001 avatar thehandsomepanther avatar yeamal avatar zach-cmiel avatar zachwise 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  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

juxtapose's Issues

Can't move slider on Android

In Android native or Chrome browsers, the slider does not respond.
Tapping the left and right edge does move the slider to 100%.
Otherwise, works great!

Photos won't match

Hi, not so much a bug, but if there's no way to tweak or crop the photos within JuxtaposeJS, even the slightest mismatch on the pictures lining up requires going back to Photoshop and recropping (blind, since Photoshop doesn't allow for this style of comparison either, as far as I know).

It's a great tool and I can't wait to start telling my students about it (I'm a J-technology professor at Loyola), but, to be very frank, it's useless to the casual user without this functionality.

Scrollbar causes misalignment of left and right image

In preview, images are aligned perfectly, but when I copy only the URL from the embed code and paste it to new window, scrollbars appear, which causes misalignment of left and right image.
http://cdn.knightlab.com/libs/juxtapose/dev/embed/index.html?uid=70523e00-280e-11e5-91b9-0e7075bba956

When I change the window width narrower (so the vertical scrollbar dissapears) and refresh the page then left and right image are aligned perfectly again.

CDN does not provide HTTPS

We just wanted to use juxtapose in a https site. The embed code says to use:

<link rel="stylesheet" href="//cdn.knightlab.com/libs/juxtapose/latest/css/juxtapose.css"><script type="text/javascript" src="//cdn.knightlab.com/libs/juxtapose/latest/js/juxtapose.js"></script>

However no https is served in the cdn - resulting the script load to fail

align "knightlab-credit" overlay with StoryMapJS

Zach has set this design precedent in StoryMapJS
image

The equivalent in Juxtapose should look more like that. Rather than import a font for that small bit, he advised that we make a PNG to inline that has both the orange diamond icon and the text.

The rules that set the text is
font-family: 12px/1.5 "Helvetica Neue",Arial,Helvetica,sans-serif
text-shadow: 0px 0px 1px #FFF, 0px 0px 1px #FFF, 0px 0px 5px #FFF;
font-size: 14px;
font-weight:bold;

Some adjustments from that might be appropriate, but something that uses Helvetica Neue and has the shadow so that the text is equally readable on light or dark backgrounds would be appropriate.

Also, the link to the Juxtapose page should open in a new window.

No need to reproduce the hover text-color change behavior for this.

Hosted images (wp, vox, nyt), two instances of the slider appear

Adding Rebekah's email:

Wanted to let you know that I got a little bug, so maybe you can give it a look. When I update with certain urls for hosted images (wp, vox, nyt), two instances of the slider appear. (Screenshots attached.)

This doesn’t happen with dropbox or imgur urls.

When I paste in google drive urls (the ones they prompt you to use), it’s not rendering at all (likely bc google wraps the files in a bunch of ui). You may want to be a bit more specific about how to paste those into the form.

PS: This is super fun with gifs!!!

Consider loading CSS from Javascript

From Zendesk tickets, it seems like a lot of people are snagged by CMSes like Wordpress stripping the tag that inlines the CSS.

I wonder if we should have some support for loading the CSS via javascript. I don't think we'd want it to always be the case, and I don't have a great idea about how to configure it, but I thought I'd log it.

Of course, #38 is a different way of addressing this issue, and maybe a nicer one.

Invalid URLs

I'm trying to make a slider using two photos of pollution in China that I recently took, but every time I put the links in, the preview goes blank/white and won't show up. I saw a post in this forum that the preview goes blank when the URL's are invalid. I've tried using links from Dropbox and Google Drive. Has anyone else had this problem and do you have a solution?

These are the links I've tried to use:
https://www.dropbox.com/s/2zhpglr1md3sbj4/JS_Clear.JPG
https://www.dropbox.com/s/znaddf7hn5aqsrd/JS_Pollution.JPG
https://drive.google.com/file/d/0B36zihP_tLchUEFIQi1oNlpqT2c/view
https://drive.google.com/file/d/0B36zihP_tLchbDF3bUgxcTRBb0k/view

Sharable GIFs of Slider

It would be cool if you could download a .gif of the slider so you could share it on social media. Not sure how to go about doing this but it seems like a cool idea.

Flickr returning small images

I'm not sure exactly what's going on here; as far as I know we haven't touched the Flickr code but it started returning really small resolution images.

screen shot 2014-09-19 at 10 54 49 am

Cannot run development server

(ref #52)

fab serve does not work:

Notice: Loaded config @ /Users/jenny/repos/juxtapose/config.json

[localhost] local: python website/app.py -p 5000
Traceback (most recent call last):
  File "website/app.py", line 22, in <module>
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (settings_module, e))
ImportError: Could not import settings 'core.settings.loc' (Is it on sys.path?): No module named secrets

Fatal error: local() encountered an error (return code 1) while executing 'python website/app.py -p 5000'

Aborting.

Also running python website/app.py does not work:

Traceback (most recent call last):
  File "website/app.py", line 22, in <module>
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (settings_module, e))
ImportError: Could not import settings 'core.settings.loc' (Is it on sys.path?): No module named secrets

Multiple Sliders on One Page

Right now the script looks for one element with the id klba-wrapper. Need to make it class based and not id based.

Does JuxtaposeJS work on Wordpress.com?

Hi. I am trying to add a juxtapose to a blog post in Wordpress.com as the instructions say in the page, but it would not work. Is the slider made to work in these blog pages?

If the background is white, it's hard to see the slider.

If the background is white, it's hard to see the slider.

screen shot 2014-11-10 at 10 19 50 am

Do we add an option to make it black? Do we programmatically check if its white and then change the color? Would it be jarring if the color of the slider was constantly changing? Tune in next week to find out the answers to all these questions.

documentation / setup, DEVELOPER.md

Hello,

I'm trying to set up a local development environment to work on an accessibility fork I may make a pull request for the website code (http://juxtapose.knightlab.com/) with. I'm running into to trouble so I have a few questions about DEVELOPER.md.

a) With this step in the setup,

git clone [email protected]:NUKnightLab/secrets.git

Running that code, I get the message:
ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.

b) Installing Python requirements:

If I run pip install -r requirements.txt

I get the message:
Downloading/unpacking Fabric==1.6.1 (from -r requirements.txt (line 1))
Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement Fabric==1.6.1 (from -r requirements.txt (line 1))
Cleaning up...
No distributions at all found for Fabric==1.6.1 (from -r requirements.txt (line 1))

Log message I got when trying to install the requirements as a screenshot:

screen shot 2014-10-13 at 9 29 22 pm

Not sure if this is an issue per se, but would appreciate your help.

Thanks,
Alison

Text too long

This is something we complain about all the time, but reading is no fun when there are too much text on one line.

screen shot 2014-06-27 at 11 25 21 am

Safari Jitter

When you drag the slider in Safari (both desktop and mobile) the right image jitters.

Labels Don't Show Up

I think this might be the same problem as Issue #11. If both images are given a data-label, the labels won't appear unless the wrapper also has data-showlabels set to true. It seems like the default options aren't being used.

i18n of Credits

The caption text are in English; it would be a lot of work to translate those couple words to all the languages. Maybe we just remove credits from the code and let people do it themselves in their CMS? If we went this route, we'd have to consider how to deprecate support for captions, as well as how that changes the design of the authoring tool.

Unclear layout

This whole area is looking really messy. It's unclear what comes first or in what order the reader should look at things. I think some separation would help.
screen shot 2014-06-27 at 10 59 48 am

Took a stab at reorganizing it, it's super janky cause it was hacked together in photoshop, more a general idea than a design.
fixx

I can try to style it if you guys need help!

Flickr without jQuery

Flickr integration doesn't work without jQuery and the tool should be dependence free.

Disable click function?

Is it possible to disable the click function on the slider?

For example, currently when a user clicks anywhere on either image the slider will move to that position (whether animate is enabled or not).

Is it possible to disable this functionality so the only way to change between the two images is to drag the slider?

Thanks.

Update Preview button

The button is not in the center so it seems to be just floating around. Maybe just anchor it to the left?
screen shot 2014-06-27 at 11 22 45 am

Prefix css classes

You should prefix all your css classes so they don't interfere with other other people's pages if they use the plugin. For example #baslider-wrapper, .baslider-slider, etc.

facilitate sizing the juxtapose?

Today I've seen two Zendesk tickets from people who don't know how to control the size of the iframe. Maybe we should help.

Idea: use JS to read the dimensions of the first image and use that to add width/height attributes to the iframe? Open to other ideas.

Clarify 'publish' in UI

I think people be at a loss to understand "publish." I'm thinking we can use the space below the button to show a message briefly explaining some things.

Perhaps the message should only show up after people press 'publish' once. It can say something like "The code to the right is for this pair of images. If you make minor adjustments above, click 'publish' again. If you're starting over…"

Maybe also we change 'publish' to 'republish', and maybe also we reveal a 'start a new juxtapose' button as part of this.

we can discuss details f2f.

Juxtapose Label

The label is pretty big for me and I think it would be better if it looked less intrusive. Maybe something like this:

label

white text with a shadow and small diamond?

Vertical Slider

Add support for vertical sliders in addition to horizontal sliders.

Animate broken in Chrome?

I'm trying the plugin for the first time today as a replacement for old code I wrote several years ago. It looks good, but I wanted to point out a couple things about the animate functions:

  • The glide-to-click-point animation works well for me in IE11-win and Firefox 33-win. But it does not work in Chrome 43.0.2357.132-win. Instead of gliding, the slider jumps to where I click. I see this issue when making my own slider locally, but I also see it on the example at https://juxtapose.knightlab.com/
  • Related to the above, the example on https://juxtapose.knightlab.com/ is broken in IE11-win. When you move the slider, both images resize (one squishes, the other gets fatter) rather than re-crop.

Also, a feature request:

Not rendering anymore

There is a syntax error on the last line of app.js that makes this not work anymore. I'm trying to fix it but it doesn't work right now.

Requirement for having both label and/or credit

Looks like we're adding an image comparison tool to Fusion (huzzah!) and JuxtaposeJS is the front-runner right now (double huzzah!).

Starting to implement and came across a question with labels and credits. What's design intent for having the display options for labels and credits default to off if values for both images aren't present?

Conflicts with prototype.js

Juxtapose produces conflicts when embedded in a site using prototype,js 1.6.1

to reproduce add

 <script src="http://prototypejs.org/assets/2009/8/31/prototype.js"></script>

to the examples.html provided in the repository

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.