Change the position of a background-image: - Javascript CSS Style Property

Javascript examples for CSS Style Property:backgroundPosition

Description

Change the position of a background-image:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button type="button" onclick="myFunction()">Get background position</button>
<br>
<div id="myDiv" style="background: url('http://java2s.com/resources/a.png') no-repeat center;height:500px;width:500px;border:1px solid black;">
</div>/*from www .  jav  a2s.  c o  m*/

<script>
function myFunction() {
    console.log(document.getElementById("myDiv").style.backgroundPosition);
}
</script>

</body>
</html>

Related Tutorials