Title: Responsive and javascript problem
Last modified: August 22, 2016

---

# Responsive and javascript problem

 *  [Papik81](https://wordpress.org/support/users/papik81/)
 * (@papik81)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/responsive-and-javascript-problem/)
 * I have two problems: I’d like to set the window into the center, but the script
   it throws on some resolutions sometimes in the right.
    So is there a way to trigger
   custom script to set the window position? Are there any callback to use it? I
   tried following code:
 *     ```
       // Resize event for reposition
       jQuery(window).bind('resize orientationchange', function($) {
       		if (document.getElementById('eModal-1'))
       		{
                   reposition();
       		}
       		else return true;
   
       			// Repositions the modal
   
       	 });
       var reposition = function() {
         // Elements must be visible before height calculation
         //$('#eModal-1, #pgwModalBackdrop').show();
       	emodal_top();
   
       	var windowWidth = $(window).width();
       	var modalWidth = $('#eModal-1 .emodal-content').first().outerWidth();
       	var modalLeft = Math.round((windowWidth - modalWidth) / 2);
       	$('#eModal-1').css('left',modalLeft);
           return true;
        }
   
        var emodal_top = function() {
        var windowHeight = $(window).height();
           var modalHeight = $('#eModal-1').outerHeight();
           var modalTop = Math.round((windowHeight - modalHeight) / 3);
           if (modalTop <= 0) {
             modalTop = 0;
           }
   
           $('#eModal-1').css('top', modalTop);
        }
         jQuery(function($){
         $( "#call-me" ).click(function() {
         $('eModal-1').bind('emodalAfterOpen', function() { alert('Reposition');reposition(); });
        });
       ```
   
 * How can I use the callback ’emodalAfterOpen’? Is this a correct way to set its
   custom position?
 * [https://wordpress.org/plugins/easy-modal/](https://wordpress.org/plugins/easy-modal/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Daniel Iser](https://wordpress.org/support/users/danieliser/)
 * (@danieliser)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/responsive-and-javascript-problem/#post-5436377)
 * Im assuming you just need to reposition it after it has already been opened?
 * Are you doing this because of window resizing etc?
 * The emodalAfterOpen is a trigger ( similar to wordpress hook ), and allows you
   to do something right after the modal is opened.
 * There are quite a few custom triggers like that throughout the modal functionality,
   everything from changeing the theme on the fly to adding custom close functionality
   is possible, such as enabling close on space bar press for instance.
 * What your looking for though would be the following jQuery method.
 * `jQuery('#eModal-1').emodal('reposition');`
 * That can be called inside a window resize function for instance
 *     ```
       jQuery(window).on('resize', function () {
           jQuery('#eModal-1').emodal('reposition');
       });
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Responsive and javascript problem’ is closed to new replies.

 * ![](https://ps.w.org/easy-modal/assets/icon-256x256.png?rev=982657)
 * [Easy Modal](https://wordpress.org/plugins/easy-modal/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/easy-modal/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/easy-modal/)
 * [Active Topics](https://wordpress.org/support/plugin/easy-modal/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/easy-modal/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/easy-modal/reviews/)

## Tags

 * [callback](https://wordpress.org/support/topic-tag/callback/)

 * 1 reply
 * 2 participants
 * Last reply from: [Daniel Iser](https://wordpress.org/support/users/danieliser/)
 * Last activity: [11 years, 6 months ago](https://wordpress.org/support/topic/responsive-and-javascript-problem/#post-5436377)
 * Status: not resolved