css - Use jquery to increase width of container by 10 rem -
how can increase width of element 10rem using jquery. issue jquery return width/height in pixels , want update height/width in other units.
example on: js bin
var $c = $('#container'); console.log($c.width()); var c = document.getelementbyid('container'); // q1. why different above one. 324 while earlier 320. see output. console.log(c.clientwidth); // q2. how update code increase width 10rem. $c.css({width: $c.width() + 10}); //it adds 10 pixels here. console.log($c.width()); my questions comments in code.
i suppose taking font-size of html element give rem, using function, you'll able retrieve if changes:
// function return initial font-size of html element var rem = function rem() { var html = document.getelementsbytagname('html')[0]; return function () { return parseint(window.getcomputedstyle(html)['fontsize']); } }(); // function convert pixel rem function torem(length) { return (parseint(length) / rem()); } example: http://jsfiddle.net/4nksu/1/
Comments
Post a Comment