我还是 HTML5 的新手,但我遇到了一个非常奇怪的行为。(在铬)
以下代码适用于 chrome:
<!DOCTYPE html>
<html>
<head>
<title>Webkit-transition test</title>
<script language="javascript" >
function addSpan()
{
document.getElementById("someDiv").innerHTML = "<span id=\"t47\" >A new span!</span>";
document.getElementById("t47").className += "letter";
}
function moveIt()
{
document.getElementById("t47").style["MozTransform"] = "translate(10px,40px)";
document.getElementById("t47").style["WebkitTransform"] = "translate(10px,40px)";
}
</script>
<style>
.letter{
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
display: inline-block;
color: red;
}
</style>
</head>
<body>
<div id="someDiv"></div>
<span class="letter" id="aaa">This is an old span</span>
<button onclick='addSpan()'>Add Span</button>
<button onclick='moveIt()'>Move it!</button>
</body>
</html>
但是,如果我移动这条线:
document.getElementById("t47").className += "letter";
到 moveIt 函数的开头,跨度只是跳跃而不过渡
javascript部分将是这样的:
<script language="javascript" >
function addSpan()
{
document.getElementById("someDiv").innerHTML = "<span id=\"t47\" >A new span!</span>";
}
function moveIt()
{
document.getElementById("t47").className += "letter";
document.getElementById("t47").style["MozTransform"] = "translate(10px,40px)";
document.getElementById("t47").style["WebkitTransform"] = "translate(10px,40px)";
}
</script>
那么这里有什么区别呢?不过,这两种情况在 Firefox 上运行良好。我没试过IE。
我很感激我能得到的任何帮助!