• 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://www.ads-software.com/plugins/easy-modal/

Viewing 1 replies (of 1 total)
  • Plugin Author Daniel Iser

    (@danieliser)

    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.