WordPress – Divi Popup

We have put together instructions on how to open a popup using a button.

1st CSS class

Assign a class to the “popup” button element

2. section and column classes

Add a section with the class name “popup-overlay”

Then insert the class name “popup-content” with something in the column.

Then add a text module for the close icon in the popup with content:

<span class="close-popup">x</span>

Then add modal text to add content to the popup and add your content.

3 Add CSS to custom CSS

.popup-overlay {
    position: fixed; 
    top: 0; 
    width: 100%; 
    height: 100vh; 
    z-index: -1; 
    justify-content: center; 
    align-items: center;  
    opacity: 0; 
    overflow: hidden;
    transition: opacity 0.4s ease-in-out; 
    -moz-transition: opacity 0.4s ease-in-out;
    -webkit-transition: opacity 0.4s ease-in-out;
  background: rgba(0,0,0,0.9);
}

.popup-overlay.show {
	  display: flex; 
	  opacity: 1; 
    z-index: 99999; 
}

span.close-popup {
    color: #fff;
    position: absolute;
    top: -53px;
    right: -32px;
    font-size: 30px;
    cursor: pointer;
}

Add jquery to show and hide the popup when clicking the button and the trigger button:

<script>
jQuery(document).ready(function( $ ) {	
    $(document).on('click', '.popup', function(event){
    event.preventDefault();
    });		
});
</script>
<script>
jQuery(document).ready(function ($) {                           
	
	$(document).on('touchstart click', '.popup', function(event){            
	event.preventDefault();                                       
	$('.popup-overlay').addClass('show');                         
    });			
	
	$(document).on('touchstart click', '.popup-overlay', function(event){    
	$('.popup-overlay').removeClass('show');                      
	});
		
	$(document).on('touchstart click', '.popup-content', function(event){    
		event.stopPropagation();                                    
	});
		
	$('.close-popup').click(function(){
	  $('.popup-overlay').removeClass('show'); 
	});
});
</script>

Adding two popups on one page

For this, all the above css, jQuery and section with column and module must be duplicated.

1) Change class names

Button – popup2

Section – popup-overlay2

Column – popup-content2

Close button – x

I have removed jQuery from this page and added it in Theme-Option->Integration, because if you duplicate the section every time, this code will also be duplicated and contradict each other.

<script>
jQuery(document).ready(function( $ ) {		
    $(document).on('click', '.popup2', function(event){
    event.preventDefault();
    });		
});
</script>
<script>
jQuery(document).ready(function ($) {                           
	$(document).on('touchstart click', '.popup2', function(event){            
	event.preventDefault();                                       
	$('.popup-overlay2').addClass('show2');                         
    });			
	$(document).on('touchstart click', '.popup-overlay2', function(event){    
	$('.popup-overlay2').removeClass('show2');                      
	});	
	$(document).on('touchstart click', '.popup-content2', function(event){    
		event.stopPropagation();                                    
	});	
$('.close-popup2').click(function(){
  $('.popup-overlay2').removeClass('show2'); 
});
});
</script>

Dieser Beitrag ist auch verfügbar auf: Deutsch (German)

Was this article helpful?

Related Articles

Submit a Comment

Your email address will not be published. Required fields are marked *

Published on - 15. Jul 2021
Modified on - 29. Mar 2024
Views - 106
Likes - 0

Do you need help?

Kontaktiere uns gerne :-)
Contact Support
Skip to content