Flat, responsive, lightweight, fast, easy customizable modal window plugin with declarative state notation and hash tracking.
Minified version size: ~4kb
#IMPORTANT!
If your page body requires height: 100%
, your page will scroll to the top(#20, #21), because remodal sets overflow: hidden
to the html and body when opening to hide a scrollbar. There is no problem if your content doesn't overflow your full height body container, otherwise you should do something of this:
- Try to set
min-height: 100%
instead ofheight: 100%
. If it doesn't help, read next. - Set
html, body { overflow: auto !important; margin: 0; }
. Your page won't be locked and will be scrollable always.
- All modern browsers are supported.
- Only webkit browsers has a blur effect in the default css theme. If you want a blur for another kind of browsers use: https://github.com/Schepp/CSS-Filters-Polyfill, but it's not fast like a native css3 blur.
- IE8+. To enable IE8 styles set
lt-ie9
class for thehtml
element, as modernizr does. - Zepto support.
That's very simple to start using Remodal.
Download it. You can use bower: bower install remodal
Add this in the head section:
<link rel="stylesheet" href="path/to/your/jquery.remodal.css">
Add this before the </body>
or in the head:
<script src="path/to/your/jquery.remodal.min.js"></script>
Define the background container for the modal(for effects like a blur). It could be any simple content wrapper:
<div class="remodal-bg">
...All your content...
</div>
And now create a modal dialog:
<div class="remodal" data-remodal-id="modal">
<h1>Remodal</h1>
<p>
Flat, responsive, lightweight, fast, easy customizable modal window plugin
with declarative state notation and hash tracking.
</p>
<br>
<a class="remodal-cancel" href="#">Cancel</a>
<a class="remodal-confirm" href="#">OK</a>
</div>
So, now you can call it with a hash:
<a href="#modal">Call the modal with data-remodal-id="modal"</a>
Or:
<a data-remodal-target="modal">Call the modal with data-remodal-id="modal"</a>
You can pass additional options by the data-remodal-options attribute.
<div class="remodal" data-remodal-id="modal"
data-remodal-options="hashTracking: false">
<h1>Remodal</h1>
<p>
Flat, responsive, lightweight, fast, easy customizable modal window plugin
with declarative state notation and hash tracking.
</p>
<br>
<a class="remodal-cancel" href="#">Cancel</a>
<a class="remodal-confirm" href="#">OK</a>
</div>
Default: true
To open a modal without a hash, use data-remodal-target
attribute.
<a data-remodal-target="modal" href="#modal">Call the modal with data-remodal-id="modal"</a>
Default: true
If set to true, closes a modal window after clicking confirm button.
Default: true
If set to true, closes a modal window after clicking cancel button.
Default: true
If set to true, closes a modal window after press ESC button.
Default: true
If set to true, closes a modal window by clicking anywhere on the page.
$(document).on('open', '.remodal', function () {
console.log('open');
});
$(document).on('opened', '.remodal', function () {
console.log('opened');
});
$(document).on('close', '.remodal', function () {
console.log('close');
});
$(document).on('closed', '.remodal', function () {
console.log('closed');
});
$(document).on('confirm', '.remodal', function () {
console.log('confirm');
});
$(document).on('cancel', '.remodal', function () {
console.log('cancel');
});
Ok, don't set class attribute and write something like this:
<script>
var options = {...};
$('[data-remodal-id=modal]').remodal(options).open();
</script>
Don't use id
attribute, if you don't want browser scrolling to the anchor point.
Get an instance of modal and call a method:
var inst = $.remodal.lookup[$('[data-remodal-id=modal]').data('remodal')];
// open a modal
inst.open();
// close a modal
inst.close();
The MIT License (MIT)
Copyright (c) 2014 Ilya Makarov, http://vodkabears.github.io
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.