Basically title. Here is the code:
const car = document.getElementById("car");
console.log(car.offsetLeft);
* {
margin: 0;
padding: 0;
}
body {
height: 100vh;
width: 100vw;
display: flex;
}
#game {
width: 98%;
height: 150px;
right: -1%;
border: 1px solid black;
top: 45%;
position: relative;
overflow: hidden;
}
#floor {
background-color: brown;
position: absolute;
width: 100%;
height: 10px;
bottom: 0px;
}
#npc1 {
background-color: red;
width: 100px;
height: 30px;
position: absolute;
bottom: 10px;
left: 500px;
animation: npc1Drive 10s linear;
}
#npc2 {
background-color: red;
width: 100px;
height: 30px;
position: absolute;
bottom: 10px;
left: 0px;
animation: npc2Drive 10s linear;
}
#car {
background-color: blue;
width: 100px;
height: 30px;
position: absolute;
bottom: 10px;
left: 250px;
}
#possible {
background-color: green;
width: 200px;
height: 30px;
position: absolute;
bottom: 10px;
left: 200px;
animation: possible 10s linear;
}
#seen {
background-color: yellow;
width: 150px;
height: 30px;
position: absolute;
bottom: 10px;
left: 225px;
animation: seen 10s linear;
}
@keyframes npc1Drive {
0% {
left: 500px;
}
100% {
left: 2480px;
}
}
@keyframes npc2Drive {
0% {
left: 0px;
}
100% {
left: 1980px;
}
}
@keyframes seen {
0% {
left: 225px;
}
100% {
left: 2205px;
}
}
@keyframes possible {
0% {
left: 200px;
}
100% {
left: 2180px;
}
}
<!DOCTYPE html>
<html>
<head>
<title>
MIH
</title>
<link rel = "stylesheet" href = "carCSS.css">
</head>
<body>
<script src = "carJS.js"></script>
<div id = "game">
<div id = "npc1"></div>
<div id = "possible"></div>
<div id = "seen"></div>
<div id = "car"></div>
<div id = "npc2"></div>
<div id = "floor"></div>
</div>
</body>
</html>
As you can see, in the snippet I get what you would expect (as seen in the CSS) - 250. That's what I also got in every online code runner. However, Visual Studio Code wants to be a special child - this it what it gives me in the console:
I'm honestly stumped. Why would it do such thing, when it clearly works everywhere else? I didn't change anything, it's a copy-paste of what I have in VS code. I would love if some of you will clear it up for me, thanks in advance!