如何将像素计算成百分比?

How to calculate pixels into percentage?

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

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

我在上面得到了这段代码,但它设置了以像素为单位的值,所以 .helper 宽度也应该以像素为单位才能完成此操作。如何将 helperPos_x 值转换为百分比?有可能吗?对此有什么想法吗?

我找到了答案。

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