JavaScript에서 배경 이미지의 시작 위치를 설정하려면 backgroundposition을 사용하세요. 재산. 이미지의 위치를 설정할 수 있습니다.
예시
다음 코드를 실행하여 JavaScript로 배경 이미지의 모든 위치를 설정하는 방법을 배울 수 있습니다 -
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-repeat: no-repeat;
}
</style>
</head>
<body>
<button onclick="display()">Click to Set background image</button>
<script>
function display() {
document.body.style.backgroundImage = "url('https://www.tutorialspoint.com/html5/images/html5-mini-logo.jpg')";
document.body.style.backgroundPosition="top right";
}
</script>
</body>
</html>