คุณสมบัติ backgroundRepeat ใช้สำหรับตั้งค่าหรือรับวิธีที่ภาพพื้นหลังทำซ้ำ (repeat) ตัวเอง
ไวยากรณ์ (Syntax)
object.style.backgroundRepeat = "repeat|repeat-x|repeat-y|no-repeat|initial|inherit"
ค่าที่ใช้ได้ (Values)
| ลำดับ | ค่าและคำอธิบาย |
|---|---|
| 1 | repeat ค่าเริ่มต้น ทำซ้ำภาพพื้นหลังทั้งแนวตั้งและแนวนอน |
| 2 | repeat-x ทำซ้ำภาพพื้นหลังเฉพาะแนวนอน |
| 3 | repeat-y ทำซ้ำภาพพื้นหลังเฉพาะแนวตั้ง |
| 4 | no-repeat ไม่ทำซ้ำภาพพื้นหลัง |
ตัวอย่าง (Example)
<!DOCTYPE html> <html> <head> <style>
body {
background-image: url("https://www.tutorialspoint.com/power_bi/images/power-bi-minilogo.jpg");
background-repeat: repeat-x;
color:black;
font-size:20px;
}
</style>
<script>
function changeBackRepeat(){
document.body.style.backgroundRepeat="repeat-y";
document.getElementById("Sample").innerHTML="The background image is now repeated vertically";
}
</script> </head>
<body>
<h2>Demo Heading</h2>
<p>This is demo text.</p>
<p>This is demo text.</p>
<p>This is demo text.</p>
<p>This is demo text.</p>
<p>Change the body background image repeat value by clicking the below button</p>
<button onclick="changeBackRepeat()">CHANGE REPEAT</button>
<p id="Sample"></p>
</body> </html>
ผลลัพธ์ (Output)
ผลลัพธ์ที่ได้:

เมื่อคลิกปุ่ม CHANGE REPEAT:
