ในการตั้งค่าพื้นที่ภาพวาดของพื้นหลังด้วย JavaScript ให้ใช้ backgroundClip คุณสมบัติ. คุณสามารถลองเรียกใช้รหัสต่อไปนี้เพื่อกำหนดพื้นที่ภาพวาดของพื้นหลัง -
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<style>
#box {
border: 2px dashed green;
padding: 35px;
width: 600px;
height: 400px;
background-color: blue;
background-clip: border-box;
}
</style>
</head>
<body>
<button onclick="display()">Set painting area</button>
<div id="box">
This is Demo Text! This is Demo Text! This is Demo Text!
This is Demo Text! This is Demo Text!
</div>
<script>
function display() {
document.getElementById("box").style.backgroundClip = "content-box";
}
</script>
</body>
</html>