Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

convert % to px javascript

// 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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #convert #px #javascript
ADD COMMENT
Topic
Name
1+3 =