📜  将 % 转换为 px javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:19.452000             🧑  作者: Mango

代码示例1
// convert px to %
var pixels = 100; // px
var screenWidth = window.screen.width; // total px across width
var percentage = ( screenWidth - pixels ) / screenWidth ; // 0.92%

// convert % to px
var percentage = 5; // % 
var screenWidth = window.screen.width; // total px across width
var pixels = Math.round(( percentage/100 ) * screenWidth) ; // 90px