日期:2014-05-16 浏览次数:20459 次
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test Range bug of fireFox</title>
<!-- <link type="text/css" rel="stylesheet" href="css/basic.css"></link> -->
<style>
.textTransform{
font:18px Simsun,arial,sans-serif;
display:block;
position:absolute;
}
.textSpanOne{
-webkit-transform: translate(31px, 4px);
-moz-transform:translate(31px, 4px);
transform:translate(31px, 4px);
}
.textSpanTwo{
-webkit-transform: translate(50px, 6px);
-moz-transform:translate(50px, 6px);
transform:translate(50px, 6px);
}
.textSpanThree{
-webkit-transform: translate(90px, 10px);
-moz-transform:translate(90px, 10px);
transform:translate(90px, 10px);
}
.textSpanFour{
-webkit-transform: translate(130px, 12px);
-moz-transform:translate(130px, 12px);
transform:translate(130px, 12px);
}
.textSpanFive{
-webkit-transform: translate(170px, 16px);
-moz-transform:translate(170px, 16px);
transform:translate(170px, 16px);
}
</style>
<script>
window.onload = function(){
//fireFox bug
var span_doms = document.getElementsByTagName('span');
for(var i = 0; i < span_doms.length; i++){
var textNode = span_doms[i].childNodes[0];//获取文本对象
var range = document.createRange();
range.setStart(textNode, 0);
range.setEnd(textNode, 0 + textNode.length);
var boundTest = range.getBoundingClientRect();//只有火狐浏览器获取的值异常
console.log(boundTest);
}
}
</script>
</head>
<body>
<h1>FireFox Range Bug </h1>
<span class="textTransform textSpanOne">这</span>
<span class="textTransform textSpanTwo">只是</span>
<span class="textTransform textSpanThree">一个</span>
<span class="textTransform textSpanFour">测试</span>
<span class="textTransform textSpanFive">文本</span>
</body>
</html>