0

I tried to get the position of the element from right. I defined the following in CSS

.container {
   position: absolute;
   right: 8%;
   bottom: 7%;
}

I tried to get the position of the element from right using the following jquery code

$('.container').css('right');

which gives 142px on chrome and mozilla

but gives 8 (percentage) on iOS(both safari and chrome) browsers.

Any other options in jQuery to get the value in px on iOS browsers and other browsers alike?

Arumai
  • 75
  • 4

2 Answers2

0

take the percentage and get the value...

var px_right = ('.container').css('right');
/* --- but --- */ 
if ( /*iOS*/ navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
    px_right = (('.container').css('right'))/100.0  * window.width();
} 

`

EDIT sorry I have forgotten a thing: /100.0. Edited:

px_right = (('.container').css('right'))/100.0 * window.width();

example : 'px_right = 8% of 980px = 0.08*980 = 78px

3pic
  • 1,188
  • 8
  • 26
  • i checked whether the result contains 'px' in it. if so, i let it be as it is. or I calculate the value depending on the enclosing container width... Thanks for the answer... – Arumai Jul 24 '15 at 20:05
0

Try to use

var style = Window.getComputedStyle($('.container')[0])
console.log(style.right);
Alex Nikulin
  • 8,194
  • 4
  • 35
  • 37