如果我将要在函数中传递的值translateX()
放在一个变量中pos
(参见下面的代码),过渡效果不会在 chrome 中显示,但在 Firefox 中可以正常工作,而通过直接在translateX()
函数中给出值,它在两者中都有效。
//javascript::
<script>
function fn()
{
var pos=100; //variable pos defines position of text
var idd="one";
var elem=document.getElementById(idd);
/*does not work in chrome*/ elem.style.cssText="transition:transform 1s;-webkit-transition:transform 1s;transform:translateX("+pos+"px);-webkit-transform:translateX("+pos+"px);";
/* works in both elem.style.cssText="transition:transform 1s;-webkit-transition:transform 1s;transform:translateX(100px);-webkit-transform:translateX(100px);";*/
}
</script>
//html ::
<body>
<div id="one" >
text
</div>
<div onclick="fn()">
click
</div>
</body>