Set a background-image to repeat horizontally or vertically: - Javascript CSS Style Property

Javascript examples for CSS Style Property:backgroundRepeat

Description

Set a background-image to repeat horizontally or vertically:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
body {//from   ww w .j  av  a2 s . co  m
    background: #f3f3f3 url('http://java2s.com/resources/a.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>

Related Tutorials