document.getElementById().style.transition 没有 return 任何值
document.getElementById().style.transition does not return any value
我有一个 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
我有一个 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