Modality makes it easy to use modal-windows in your HTML5 project. It's framework independent; versatile; and hopefully you'll find it easy to work with. Features include:
The modal is built using a BEM CSS model, resulting in the following fundamental component HTML:
The .modality wrapper can contain multiple .Modality-window elements and will only display the top element in the stack, i.e. the last .Modality-window inside the .Modality-container element.
The appearance of the modal is (of course) styled completely using CSS, so you can easily change it to fit your specific project, but the positioning of the individual Modality-windows is done using JavaScript.
.Modality wrapper element excludedIn the below example, the .modal wrapper element has been disabled to prevent the remainder of the Modality-test-examples on this page from adding themselves to the wrapper-element.
In order to get the below test-example to display the modal correctly, style="position: relative;" has been added to the .Modality-container element which is otherwise absolutely positioned.
In order to get the below test-example to display the modal correctly, style="display: block;" has been added to the .Modality-container element which is otherwise absolutely positioned.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In vitae ipsum sit amet nulla bibendum rhoncus. Nulla augue nisl, fermentum quis hendrerit sed, fermentum at mauris. Cras sodales risus vel nisi pellentesque rhoncus. Praesent vulputate dolor nisi, id pharetra nisi varius eu. Fusce non auctor dui. Quisque a ullamcorper nisi. Integer laoreet velit et suscipit luctus.
Modality-window--alert added to remainder of test casesIn order to display modals realistically, i.e. displaying a modal that doesn't fill the entire width of the screen, the remainder of the test-examples all contain a Modality-window modifier-class.
The JavaScript function(s) that are initiated by the onReady-callback function are inlined as part of the 'test-example' element.
autofocus="autofocus"If the HTML content your filling into the modal contains a form element with autofocus="autofocus" it will most likely make the page scroll when loading the modal.
Instead use the formFieldFocus: true property (enabled by default), which will set focus to the first non-hidden form-field in the modal window.
So why be able to update modals in the first place? Well, sometimes you might want to show the modal with an AJAX-loader while for instance AJAX-requesting the content.
The below example launches a (confirm) modal, which is subsequently updated upon confirm.