Using JavaScript

We can also open and close Popups with JavaScript, for this we need to look at related App methods:

$.popup(popup) - Open Popup

$.closeModal(popup) - Close Popup

{% highlight html %}

Popup(JavaScript)

...
{% endhighlight %} {% highlight js %} $(document).on('click','.open-about', function () { $.popup('.popup-about'); }); $(document).on('click','.open-services', function () { $.popup('.popup-services'); }); {% endhighlight %}

Popup Events

Popup has the same events as Modals, they could be useful when you need to do something in JavaScript when Popup opened/closed

Event Target Description
open Popup Element<div class="popup"> Event will be triggered when Popup starts its opening animation
opened Popup Element<div class="popup"> Event will be triggered after Popup completes its opening animation
close Popup Element<div class="popup"> Event will be triggered when Popup starts its closing animation
closed Popup Element<div class="popup"> Event will be triggered after Popup completes its closing animation
{% highlight html %}

Popup Events

...
{% endhighlight %} {% highlight js %} $(document).on('click','.popup-about', function () { console.log('About Popup opened') }); $(document).on('click','.popup-about', function () { console.log('About Popup is closing') }); $(document).on('click','.popup-services', function () { console.log('Services Popup is opening') }); $(document).on('click','.popup-services', function () { console.log('Services Popup is closed') }); {% endhighlight %}

Dynamic Popup

Light7 allows you to create Popup dynamically by passing its HTML to related methods:

$.popup(popupHTML, removeOnClose) - Open Popup

{% highlight html %}

Dynamic Popup

...
{% endhighlight %} {% highlight js %} $(document).on('click','.create-popup', function () { var popupHTML = '' $.popup(popupHTML); }); {% endhighlight %}