Coder Social home page Coder Social logo

drublic / css-modal Goto Github PK

View Code? Open in Web Editor NEW
1.8K 63.0 212.0 3.42 MB

A modal built with pure CSS, enhanced with JavaScript

Home Page: https://drublic.github.io/css-modal

License: MIT License

JavaScript 63.15% CSS 20.93% HTML 15.92%
css css-modal sass plugin

css-modal's Introduction

CSS Modals Build Status

Modals built out of pure CSS

Please visit the website to read more about this project and refer to the FAQ in case of a question.

What is it

Built with pure CSS: CSS Modal is built out of pure CSS. JavaScript is only for sugar. This makes them perfectly accessible.

Optimized for mobile: The modals are designed using responsive web design methods. They work on all screen sizes from a small mobile phone up to high resolution screens.

Use as Sass plugin: You can use CSS Modal as Sass plugin and apply it to your custom classes. No need to understand all the code.

A few other advantages: Accessible, cross-browser, media-adaptive, small and fast!

How to use

Please be aware that modals get stacked above each other if you open one modal from within another. You can add a data-attribute data-stackable="false" to the modal in order to make it non-stackable.

Markup

You need to include the markup and content for modals in your website. This has a positive effect on SEO. The example code:

<section class="modal--show" id="modal-text" tabindex="-1"
        role="dialog" aria-labelledby="modal-label" aria-hidden="true">

    <div class="modal-inner">
        <header id="modal-label"><!-- Header --></header>
        <div class="modal-content"><!-- The modals content --></div>
        <footer><!-- Footer --></footer>
    </div>

    <a href="#!" class="modal-close" title="Close this modal" data-close="Close"
        data-dismiss="modal">?</a>
</section>

The id attribute is the one which identifies the modal. You can link to this ID from everywhere.

Please note that the ID cannot include the / character since this one is needed for identifying stacked modals.

Using header and footer is optional. Just remove the tags if you don't want them in a modal.

You should leave the link's href attribute that way to close the modal in order to prevent the page from scrolling to top when clicking on it.

Please remember to set a unique ID for the header and change the aria-labelledby attribute to the same value.

You link to a modal by simply setting the ID to a link element's href like this:

<a href="#modal">Modal</a>

If you want to decouple the modal call from the location's hash you need to add data-cssmodal-nohash to the link.

JavaScript

As stated above you don't need JavaScript to get a good experience out of CSS Modals. But there are some issues where JavaScript helps:

  • IE 8 compatibility (please include jQuery if you need full compatibility).
  • Pressing escape: If you press ESC on your keyboard while the modal is visible it closes itself. This behavior cannot be achieved with CSS only.
  • Preventing background page from scrolling: If you scroll within the modal and you reach the end you don't want the page in the background to scroll. To prevent this JavaScript pushes a CSS class selector to the body element.
  • Being accessible: To get the browser's focus to the modal and back after closing.
  • Firing events: When a modal opens a custom event is fired called cssmodal:show. When the modal is hidden, an event called cssmodal:hide is triggered.
  • To add this behavior to your website, please include the JavaScript file modal.js right before the closing body-tag:
<script src="js/modal.js"></script>

Browser Support

This modal is designed to work on all modern browsers. Unfortunately this does not include Internet Explorer 7 or lower. But we deal with IE 8 – well,… at least it works.

On mobile Safari for iOS and Android 4+ it is tested pretty well, while Android 2.3 has some problems (biggest issue is scrolling). It's also working on Windows Phone 8.

In numbers:

  • Chrome
  • Firefox
  • Safari 6.x
  • Opera 12+
  • Internet Explorer 8 (functional, include jQuery if you want support for events)
  • Internet Explorer 9+
  • iOS 6
  • Android 2.3 (functional)
  • Android 4.x
  • Windows Phone 8

Media

Please be aware that you need to stop playing videos or audio manually after hiding the modal. We have a plugin for this though.

Events

There is an event cssmodal:show fired on the modal itself after the modal is shown. Another event cssmodal:hide is fired after the modal is hidden.

You can use the events by subscribing to them as if they were click events or something. Here is an example using jQuery:

$(document).on('cssmodal:show', function (event) {
    console.log(event);
});

There events are not fired in IE8. Please be aware of that and use jQuery or something else to create custom events.

Plugins

We have a couple for the modal to enhance it:

  • Resize - Resizes modal to size of input elements
  • Gallery - A lightbox plugin (in connection with resize)
  • HTML5 Video - Load videos within the modal
  • Maximum Width - Set a custom maximum width on a per-modal basis

Bug reports and feature requests

If you got something that's worth including into the project please open an issue for further discussion.

Please see the section on contributing on the website.

Contributors

This is a project by Hans Christian Reinl. Thanks goes out to all other contributors.

css-modal's People

Contributors

4nduril avatar adriaanbaelus avatar anselm-urban avatar anselmh avatar ben-m avatar benschwarz avatar bitdeli-chef avatar drublic avatar fabien-d avatar grayghostvisuals avatar jgadbois avatar kittygiraudel avatar kkirsche avatar melros avatar michaelthorne avatar noordawod avatar ppowalowski avatar realmyst avatar schepp avatar sylvaincombes avatar tzi avatar xhmikosr 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

css-modal's Issues

Research hardware acceleration for modal animation

When using fixed (position: fixed) elements on a page in connection with the hardware accelerated modal, the fixed elements are likely to break.
This problem only occurs in Webkit browsers. This does not happen on iOS, Android not tested yet.

There are two possible solutions:

  1. Media Query for hardware accelerated transitions. This is not clean as desktop-browsers might match these anyway.
  2. Using -webkit-transform-style: preserve-3d (maybe in connection with -webkit-backface-visibility: visible).

This needs to be researched further.

Page jumps to top

When you click on one of the examples on the demo page the page jumps to the top.
That's not optimal since you have to scroll back down, once you dismiss the modal.

Better handling of keyboard navigation to be "accessible"?

As the term "accessible" is being used here, it's worth noting that ideally the modal should handle keyboard navigation a bit better - if it acts as a true modal, users that navigate via keyboard should, after opening the modal, only be able to tab/shift+tab through the links/elements of the modal itself until it's closed. this will require some additional JS to set initial focus into the modal, make sure that focus stays/cycles within the modal itself, and is returned back to the main page after the modal is closed.

Demo with pictures - are thumbnails meant to be clickable?

Very nice module btw :)

Is anything meant to happen on the demo with pictures - A slideshow, or perhaps the thumbnails are clickable? For me the modal opens and I see the main pic with thumbnails underneath, but nothing else happens.

I'm on OS X 10.8.3 and Chrome 26.0.1410.65.

Update for website

The website is now in gh-pages exclusively.
We need to update and represent the latest changes of the repo in a good way. One big feature is stackable modal. Also the LESS branch needs some attention.

IOS question

Can't get modal window to fit safari/iphone5 (jumps to bottom of window and doesn't re-size) - any tips really welcome...
Works so well in everything else.

Bower is a pain w/customization

Love this, but one problem I have is bower. Bower is very powerful, but for things u really won't touch.

Tried using this project on bower, but wanted to change a whole load of stuff. Padding on the inner modal div, border color, width, breakpoints etc.

Maybe one of these days we can actually take advantage of a better package mgt. system. I just don't think we are there yet with them.

Set aria-labelledby & id attributes via JS

Although it is nice to have that extra a11y piece in place I would suggest setting aria-labelledby and the corresponding id on a dialog's header part via JavaScript.

Why? I expect most people to copy & paste dialog code and to forget to adjust id and aria attributes accordingly. Also I suspect most users of your modal lib will not have the background needed to identify this problem.

By moving this part to JS you ensure a much better a11y across the board.

Modal doesn´t show up in IE 10

The modal on my website doesn´t show up in IE10!

Here´s my code:

<a href="#twitter" class="topButton call-modal" title="Show my Twitter feed"><span class="icon-twitter"></span></a>
<figure class="semantic-content" id="twitter" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-inner">
        <div class="modal-content"><a class="twitter-timeline" height="500" href="https://twitter.com/anselm_urban" data-widget-id="280297923747647489">@anselm_urban´s tweets</a></div>
    </div>
    <a href="#!" class="modal-close" data-dismiss="modal">×</a>
</figure>

Update: works with JS.

How to increase modal-content height?

Good works guys, have used this in two web projects already.

Looking through the css and made some adjustment but it doesnt seem to work....how do one increase the height of the modal windows? the .modal-content if you will.

Thanks.

Suggestion on Modal's markup

Hi guys,

My suggestion is to remove the <header> and the <footer> tags from the modal's markup.

I'm more supporter of the view that specific markup for a webpage should be reserved for their real use, and not miss-use it as in the modal's case.

I don't like there to be several headers and footer on a same page. I believe the <header> and <footer> tags should be reserved for the page's logo, navigation, any footer content, footer navigation and copyright information.

That's all. I believe that for a more beautiful markup and and other SEO matters if these exist, I'd rather remove the mentioned tags.

Thanks a lot,
Santiago

IE (including 10) does not open modals from other modals

If one modal is opened and you want to open another modal (later maybe stackable modals) Internet Explorer in all versions does not interpret the hash change correctly and closes the current modal without opening the new one.
IE8 doesn't even close the current modal.

Revisit event dispatcher - use `new Event`

Currently we use document.createEvent which is the old way to trigger events. The new way is something like this:

var elem = document.getElementById('myForm');
var event = new Event('submit');
elem.dispatchEvent(event);

Add different modal animation styles

The desktop version of the modal can have some different styles on how to show the modal. Currently we only have fade-in.

Here's a list of cool effects we could or already have implemented:

This could be more of a add on to the plugin rater than a must have.

If anyone is fancy on implementing some of these please ping in the issue.

Android 2.3: Scrolling in modal fails

Scrolling in modals is not working on Android 2.3. The same issue appears on iOS 4.2 (which isn't really a problem at the moment). Maybe it is possible to work around this issue using JavaScript.

Multiple YouTube videos bug

Hi guys,

I'd like to submit an update request. I'm experiencing a bug when trying to "load" or "use" multiple modal boxes with different YouTube iFrame's each (one vid for each modal).

However, when I click for instance in modal 1, and then close it (with or without having played the video), and then click to open modal 2 (containing another video), the same video that was on modal one shows up. BUT if I refresh the page, and open modal 2 first, then that video will show up in modal 1 instead.

Don't understand what's going on... I'm anyways no jQuery expert so... I'd love to know if anyone knows how to fix this.

Thanks a lot,
Santiago Baigorria

ESC-Key prevents image loading in IE(9)

The ESC-Key method (JS) to close a modal prevents loading other modal images in IE9. Means you call one modal with an image included, close this via ESC-Key. Then open another one with an image inside and the image is not loaded anymore.
Maybe it needs preventDefault?

Opera modal close

In Opera the modal close button is active also when modal is not opened. This leads to serious page navigation problems in some cases as the whole content outside of .modal-inner is triggered for modal-close.

inner scrolling buggy on Firefox

inner scrolling of images (image higher than modal container) is buggy: When scrolling down in Firefox (stable, v17) the image turns black. Scrolling up it shows up again.

Can show you a video if needed.

Suggested IE8 Adjustments

Since the modal reverts to a cropped window with a scrollbar in IE8, I suggest doing the following:

// Content Area
.modal-inner {
    .lt-ie9 & {
        background: transparent;
        height: 100%;
    }
}

.modal-content {
    .lt-ie9 & {
        overflow: visible;
    }
}

This looks a bit cleaner by removing the cropped window and scrollbar. Also another suggestion would be to increase the transparency for the base64 data URI with the IE8 overlay. Gives a bit more contrast for the content.

A bit of a bummer with the IE class names as it assumes you have conditional tags around the HTML tag.

Oh and here is the new data URI for the IE8 overlay. 90% alpha channel.

background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAFo9M/3AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyNpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNS1jMDE0IDc5LjE1MTQ4MSwgMjAxMy8wMy8xMy0xMjowOToxNSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIChNYWNpbnRvc2gpIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOkQ1MjlFRTc5MEVBMzExRTM4RTJGOUYxNjgwODA3RDA3IiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOkQ1MjlFRTdBMEVBMzExRTM4RTJGOUYxNjgwODA3RDA3Ij4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6RDUyOUVFNzcwRUEzMTFFMzhFMkY5RjE2ODA4MDdEMDciIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6RDUyOUVFNzgwRUEzMTFFMzhFMkY5RjE2ODA4MDdEMDciLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz69n3R4AAAARUlEQVR42mJkYGB4BsQMTAxQABBAjBgiAAEEF4EBJgY0ABBAhFUQFgAIIAwzCOqgvgKAABoMbhgMCgACjGA4jBowIgwAAOMoDMMrMcsSAAAAAElFTkSuQmCC);

Lightbox Sizing

  1. Ability to handle sizing adjustments when viewport is resized upwards.
  2. Ability to handle multiple sizes instead of a global size set by a variable.

How to open model in javascript

Hello

I was wondering how can I open a modal box in javascript code. So I want it to open not a a click event but on a manually triggered event.

I want to perform an ajax in the

$.ajax({
        url: "basket.php?action=add&"+values,
        cache: false,
        method: "GET",
        async: false,
        complete: function(request) {
            // FIRE EVENT TO OPEN MODAL BOX 
                        //

            return false;
        }
    });

    return false;
}

how can I do this ?

Thanks in advance

Is it possible to show modal on page load?

I would love to use this modal on my site, but I need it to load on page load instead of when someone clicks a link. Is this possible? I have tried using JQuery to simulate a click but that didn't work.

Thanks! Great work on the project.

Decouple show/hide mechanism from hash when JS available

My suggestion would be to decouple visibility of the modal from the hash once JS is available - reason being that this leaves the page's author with the possibility of using the hash as a means of navigation through his site (be it hashbang based or not).

This would also open ways to stack multiple modals on top of each other.

z-index values as variables

Do z-index values as variable which can be set by user. This gives an easy possibility to users of the modal to set the z-index properly and not always set it to the maximum values.

How to open modal on page load?

Is there a way to open the model on page load instead of by clicking a link?

(this isn't an "issue" but I'm not sure how to post a question, sorry if I broke protocol)

Support dynamic content

I'd like to see support for loading content via AJAX. My usecase is that I have a list of items, and I'd like to open / view an item in a modal. It's not feasible to include the markup for every modal in the DOM, since this would be too much content.

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.