Search code examples
javascriptjqueryoffsetpercentage

How to calculate pixels into percentage?


var helperPos_x = $('.helper').offset().left;

$('.box').css('left', helperPos_x + helper_width + 'px');

I got this code above but it sets the value in pixels so .helper width should also be in pixels to accomplish this. How can I turn helperPos_x value into percentage? Is it possible at all? Any ideas about this?


Solution

  • I found the answer for this.

    helperPos_x = ($('.helper').offset().left / $(window).width() * 100);