看Chrome的newtab页里,有一个测量文字宽度的实现方法,具体的代码在下面。
想请教的是,pxWidth里的那个measuringDiv.clientWidth * 1.15 里的1.15是怎么来的,谢谢!
/**
* Fills in an invisible div with the 'Most Visited' string so that
* its length may be measured and the nav dots sized accordingly.
*/
function measureNavDots() {
var measuringDiv = $('fontMeasuringDiv');
measuringDiv.textContent = localStrings.getString('mostvisited');
var pxWidth = Math.max(measuringDiv.clientWidth * 1.15, 80);
var styleElement = document.createElement('style');
styleElement.type = 'text/css';
// max-width is used because if we run out of space, the nav dots will be
// shrunk.
styleElement.textContent = '.dot { max-width: ' + pxWidth + 'px; }';
document.querySelector('head').appendChild(styleElement);
}
想请教的是,pxWidth里的那个measuringDiv.clientWidth * 1.15 里的1.15是怎么来的,谢谢!
/**
* Fills in an invisible div with the 'Most Visited' string so that
* its length may be measured and the nav dots sized accordingly.
*/
function measureNavDots() {
var measuringDiv = $('fontMeasuringDiv');
measuringDiv.textContent = localStrings.getString('mostvisited');
var pxWidth = Math.max(measuringDiv.clientWidth * 1.15, 80);
var styleElement = document.createElement('style');
styleElement.type = 'text/css';
// max-width is used because if we run out of space, the nav dots will be
// shrunk.
styleElement.textContent = '.dot { max-width: ' + pxWidth + 'px; }';
document.querySelector('head').appendChild(styleElement);
}