I have an image like you can see below and I want to set the Images Background position for different percentage values (0%, 25%, 50%, ...)
.
---> Like for example I want to call a function with myfunction(50%)
and the Images-background should move about 50% to the left.
Please have a look at my code:
function call(value) {
document.getElementById("img").style.backgroundPositionX = -value + "px"
}
#img {
position: fixed;
left: 0%;
width: 100%;
height: 20%;
top: 0%;
background:url("https://i.stack.imgur.com/fTyE3.png") no-repeat;
background-size:cover;
}
<div id="img"><br></div>
<br><br><br>
<input type="text" oninput="call(this.value)"/>
My idea was to set the to a percent value (in this case "50%")
elem.backgroundPositionX = "50%"
...but is doesn't seems working this way!
I have no clue how to fix this problem. I don't want to use px-values. I want to set the position in percentage.
Any help would be very appreciated. Thanks in advance.