JavaScript에서 배경 이미지의 위치 지정 영역을 설정하려면 backgroundOrigin 재산.
예시
다음 코드를 실행하여 배경 이미지의 위치 지정 영역을 설정하는 방법을 배울 수 있습니다 -
<!DOCTYPE html>
<html>
<head>
<style>
#box {
border: 2px dashed yellow;
padding: 35px;
width: 600px;
height: 400px;
background: url('https://www.tutorialspoint.com/videotutorials/images/coding_ground_home.jpg') no-repeat;
}
</style>
</head>
<body>
<button onclick="display()">Set area of background image</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.backgroundOrigin = "content-box";
}
</script>
</body>
</html>