我想更改图像位置(x,y)或(上/左)我不确定有什么不同..我能够获得图像的当前坐标,但我无法更改它..我试着做:var ball = document.getElementById("ball");ball.x = 50;但它并没有改变它。这是完整的代码:<html onmousemove="showCoords(event)"><head></head><body> <img id='ball' src="ball.png" alt="Logo"style="margin-left: 50%; margin-right: auto; margin-top: 25%;width:70px;height:70px;"> <p id="demo"></p> <script> function showCoords(event) { var x = event.clientX; var y = event.clientY; var ball = document.getElementById("ball"); var ballX = ball.getBoundingClientRect().x; var ballY = ball.getBoundingClientRect().y; var mouse = "mouse: X coords: " + x + ", Y coords: " + y + ' Ball: X coords: ' + ballX + ', Y coords: ' + ballY; document.getElementById("demo").innerHTML = mouse; if(x < 100) // it does enter this statement { ball.getBoundingClientRect().x += 500; // not doing anything } } </script></body>我想也许它与图像的位置有关,但是我无法让它工作..
添加回答
举报
0/150
提交
取消