我想更改圖像位置(x,y)或(上/左)我不確定有什么不同..我能夠獲得圖像的當(dāng)前坐標(biāo),但我無法更改它..我試著做: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>我想也許它與圖像的位置有關(guān),但是我無法讓它工作..
如何在javascript中更改圖像的坐標(biāo)?
湖上湖
2021-06-29 01:12:01