คุณสมบัติ backgroundOrigin ใช้ตั้งค่าหรือรับต้นทางของพื้นหลัง (background origin) คือตำแหน่งสัมพัทธ์ สามารถสัมพันธ์กับพื้นที่ 4 พื้นที่ของ box model ได้
ไวยากรณ์ (Syntax)
object.style.backgroundOrigin = "padding-box|border-box|content-box|initial|inherit"
ค่าที่ใช้ได้ (Values)
| ลำดับ | ค่าและคำอธิบาย |
|---|---|
| 1 | padding-box จัดตำแหน่งภาพพื้นหลังสัมพันธ์กับ padding box เป็นค่าเริ่มต้น |
| 2 | border-box จัดตำแหน่งภาพพื้นหลังสัมพันธ์กับ border box |
| 3 | content-box จัดตำแหน่งภาพพื้นหลังสัมพันธ์กับ content box |
| 4 | initial ตั้งค่าคุณสมบัติให้เป็นค่าเริ่มต้น |
| 5 | inherit สืบทอดคุณสมบัตินี้จากองค์ประกอบพาเรนต์ |
ตัวอย่าง (Example)
<!DOCTYPE html> <html> <head> <style>
#DIV1 {
margin: 20px;
box-shadow: 0 0 5px black;
padding: 30px;
background: url("https://www.tutorialspoint.com/power_bi/images/power-bi-minilogo.jpg");
background-origin: content-box;
background-repeat: no-repeat;
background-size: cover;
font-size: 24px;
}
div>p {
box-shadow: 0 0 5px darkgrey;
}
</style>
<script>
function changeBackOrigin(){
document.getElementById("DIV1").style.backgroundOrigin="padding-box";
document.getElementById("Sample").innerHTML="The background origin is now set to to padding-box";
}
</script> </head>
<body>
<h2>PowerBI Tutorial</h2>
<div id="DIV1">
<p>Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI...Learn PowerBI... Learn PowerBI...Learn PowerBI...</p>
</div>
<p>Change the above div background origin by clicking the below button</p>
<button onclick="changeBackOrigin()">CHANGE ORIGIN</button>
<p id="Sample"></p>
</body> </html>
ผลลัพธ์ (Output)
ผลลัพธ์ที่ได้:

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