Javascript set left style doesn't work

前端 未结 1 862
陌清茗
陌清茗 2021-01-26 03:51
xpos=xpos+1;
document.getElementById(\"img\").style.left=xpos;

I can\'t assign xpos value to left property in javascript.

相关标签:
1条回答
  • 2021-01-26 04:33

    Try adding a unit to it. Otherwise it's probably not being read by the browser due to it being invalid CSS

    document.getElementById("img").style.left= xpos + "px";
    

    You can usually figure out these kind of things by looking at the styles pane of your browser's developer tools

    0 讨论(0)
提交回复
热议问题