Magento 2 – How to Set Custom Class for Modal Popup

magento2modalpopup

I have different popups and each popup has different styles, Anyone know how I can restyle each Modal by adding custom class or something.

Here one of my modal popup code:

<script type="text/javascript">
    require(
        [
            'jquery',
            'Magento_Ui/js/modal/modal'
        ],
        function(
            $,
            modal
        ) {
            var options = {
                type: 'popup',
                responsive: true,
                innerScroll: true,
                title: 'Popup1',
                buttons: [{
                    text: $.mage.__('Continue'),
                    class: 'btn_class',
                    click: function () {
                        this.closeModal();
                    }
                }]
            };

            $(".btn_open").click(function() {

                $(".popup_content").modal(options).modal('openModal');

            });
        }
    );
</script>

<span class="btn_open">Get first popup</span>
<div class="popup_content">First popup content</div>

Best Answer

You could use "modalClass" to set a particular class for each modal. See all of the possible modal paremeters in the following file:

 vendor/magento/module-ui/view/base/web/js/modal/modal.js
Related Topic