Javascript DOM CSS Style backgroundRepeat Property repeat horizontally or vertically

Introduction

Set a background-image to repeat horizontally or vertically:

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
body {/*from   w w  w  .  j  a  v a 2 s.  c  o m*/
  background: #f3f3f3 url('image2.png');
}
</style>
</head>
<body>

<h1>Hello World!</h1>

<button type="button" onclick="repeatVert()">Repeat background image only vertically</button>
<button type="button" onclick="repeatHori()">Repeat background image only horizontally</button>

<script>
function repeatVert() {
  document.body.style.backgroundRepeat = "repeat-y";
}

function repeatHori() {
  document.body.style.backgroundRepeat = "repeat-x";
}
</script>

</body>
</html>



PreviousNext

Related