Page 1 of 1

Centering content vertically works in browsers but not in Xcode simulator or Appery.io Tester

Posted: Wed Feb 19, 2014 4:01 am
by Victor Fagerström

In my app I use this code to center a div with content vertically:

//contdiv is a div with the size of mobilecontent.
$(window).load(function (){
var contdiv = $('.contdiv');
var contdivHeight = +$(contdiv).height();
var contdivHeight2 = contdivHeight / 2;
var contdivHeight3 = contdivHeight2 - contdivHeight;
//contentdiv is the div with content that should be centered on page.
Appery('contentdiv').css('position', 'absolute');
Appery('contentdiv').css('top', '50%');
Appery('contentdiv').css('margin-top', contdivHeight3);
});

It works as expected in all web browsers and mobile browsers but the code does nothing in appery.io tester on mobile or in Xcode simulator.

I have tried running code on pageshow event etc but only the above solution gets the right height and centers properly.

Why is this and how can I achieve this result not only in browsers, but in real app?

Image

Thanks, V


Centering content vertically works in browsers but not in Xcode simulator or Appery.io Tester

Posted: Wed Feb 19, 2014 4:21 am
by Igor

Centering content vertically works in browsers but not in Xcode simulator or Appery.io Tester

Posted: Wed Feb 19, 2014 4:32 am
by Victor Fagerström

Thank you but that covers centering Horizontally: ---
I'm talking about centering Vertically: |||.


Centering content vertically works in browsers but not in Xcode simulator or Appery.io Tester

Posted: Wed Feb 19, 2014 7:30 pm
by Maryna Brodina

Hello! There is no guarantee app will work as expected on simulator...You would need to test it on real device.