Thursday, December 6, 2012

style.backgroundRepeat

Properti style.backgroundRepeat berguna ketika BACKGROUND atau BACKGROUND-IMAGE digunakan, di mana style.backgroundRepeat mengatur tampilan pengulangan dari gambar.

Sintaks:

obj.style.backgroundRepeat = value;

Nilainya:

  • repeat (default)
    Gambar ditampilkan berulang-ulang baik horisontal dan vertikal.
  • no-repeat
    Gambar tidak ditampilkan berulang-ulang baik horisontal dan vertikal.
  • repeat-x
    Gambar ditampilkan berulang-ulang hanya secara horisontal.
  • repeat-y
    Gambar ditampilkan berulang-ulang hanya secara vertikal.
  • inherit

Contoh 1:

<HTML> <HEAD> <TITLE>style.backgroundRepeat</TITLE> </HEAD> <BODY> <SCRIPT TYPE="text/javascript"> var bodyElem = document.getElementsByTagName("body")[0]; bodyElem.style.backgroundImage = "url(picture.gif)"; bodyElem.style.backgroundRepeat = "no-repeat"; bodyElem.style.backgroundPosition = "center center"; </SCRIPT> </BODY> </HTML>

Contoh 2:

<HTML> <HEAD> <TITLE>style.backgroundRepeat</TITLE> <STYLE TYPE="text/css"> body { background: url(picture.gif) no-repeat; } </STYLE> <SCRIPT TYPE="text/javascript"> function changeRepeat() { var list = document.forms[0].listRepeat; document.body.style.backgroundRepeat = list.options[list.selectedIndex].text; } </SCRIPT> </HEAD> <BODY> <FORM> <SELECT NAME="listRepeat" onChange="changeRepeat()"> <OPTION SELECTED>repeat <OPTION>no-repeat <OPTION>repeat-x <OPTION>repeat-y </SELECT> </FORM> </BODY> </HTML>