0

Not left buttons

https://code.sololearn.com/W6a10a134A20/?ref=app So, both of my buttons end up making the "player" go to the right, even though my left butto says to make it go backwards, or to the left. i tested it with console logs, so the buttons are seperate, but left just doesn't work right. Where did i to wrong, and what do i change to make it work right?

10th Feb 2021, 6:15 PM
MeRrikK
MeRrikK - avatar
1 Antwort
0
one quick dirty fix could be to set body margin (at least margin-left) to zero... one better fix would be to use bounding box of element to get its left property to wich you substract the body marginLeft computed style: //going to the left function left() { var box = player.getBoundingClientRect(); var mleft = parseFloat(getComputedStyle(document.body).marginLeft); player.style.left = box.left - mleft - 2 + 'px'; } //going to the right function right() { var box = player.getBoundingClientRect(); var mleft = parseFloat(getComputedStyle(document.body).marginLeft); player.style.left = box.left - mleft + 2 + 'px'; }
10th Feb 2021, 6:43 PM
visph
visph - avatar