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
©2020 All rights reserved.