document.getElementById().style.transition不返回任何值



我有一个id为'he'的div元素,它的css属性是position: fixed;left: 0;

javascript:

var dief = document.getElementById('he');
//this gets a random value within the dimensions of the page so that the object does not move
var mh = Math.floor(Math.random() * window.innerHeight);
//this should set the transition to be mh/50, but it does not apply
dief.style.transition = "transition: left "+mh/50+"s linear;";
//this sets the position 
dief.style.left = mh+"px";

样式属性中不需要'transition'属性和分号。

未测试:

dief.style.transition = "left "+mh/50+"s linear";

看看:https://www.w3schools.com/jsref/prop_style_transition.asp

最新更新