Javascript DOM HTML Body set background position

Introduction

Change the position of a background-image:

document.body.style.backgroundPosition = "top right";

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
body {/*from   w  ww  . j  a  v  a2 s .co  m*/
  background-image: url('image1.png');
  background-repeat: no-repeat;
}
</style>
</head>
<body>

<button type="button" onclick="myFunction()">Position background image</button>

<script>
function myFunction() {
  document.body.style.backgroundPosition="top right";
}
</script>

</body>
</html>



PreviousNext

Related