1. Download and unpack the latest version of hystModal
Download HystModal (v0.4)
GitHub
2.Connect hystmodal.min.js and hystmodal.min.css to the page:
<link rel="stylesheet" href="hystmodal.min.css">
<script src="hystmodal.min.js"></script>
Best practices is put the <script> tag before closing <body> tag
3.Put the following markup in your HTML document:
<div class="hystmodal" id="myModal" aria-hidden="true">
<div class="hystmodal__wrap">
<div class="hystmodal__window" role="dialog" aria-modal="true">
<button data-hystclose class="hystmodal__close">Закрыть</button>
<!-- You modal HTML markup -->
</div>
</div>
</div>
.hystmodal - Main selector of the modal. It must have a unique id attribure. This selector don't get focus when modal is closed, due CSS rules visbility:hidden. Attribute aria-hidden is switches automatically.
.hystmodal__wrap - scrolled area under the modal window. Due of settings, it can close modal window on click/tap. This selecor don't have background by default. Selector .hystmodal__shadow, which obscures the page content is added automatically directly before closing <body> tag, when the script is loaded.
.hystmodal__window - Modal box. WAI-ARIA recommends adding attribute aria-labelledby with descriptions of the modal for better accessibility.
[data-hystclose] - selector with data-hystclose attribute is closing current modal window on mouse click, if this set on in configuration. This selector may contains in any place inside .hystmodal__window. If add .hystmodal__close class to the button, it will be styled like an icon.
4.Place following JS code for activating functionality of modals:
const myModal = new HystModal({
linkAttributeName: "data-hystmodal",
//settings (optional). see API
});
5.Add attribute data-hystmodal on element that will be opening the modal window. Value of the attribute must be CSS selector (id or class name of the window). For example:
<a href="#" data-hystmodal="#myModal">Open modal with id=myModal</a>
Title of data-attribute, which opening the modals, is defined by value of the property linkAttributeName of the configurations object. By defaults, it is data-hystmodal.
6.If necessary, change the configuration.