In this code snippet, I have utilized three separate div elements: one for the background image, another for a background overlay (to create a tint), and a cropped region.
The cropped region shares the same background-image as the background image div, but with the background position adjusted to negative values according to the dimensions of the crop.
const cropDiv = document.querySelector(".croppedRegion");
let setCropRegion = function(x1, y1, x2, y2) {
cropDiv.style.backgroundPositionX = `${-x1}px`;
cropDiv.style.backgroundPositionY = `${-y1}px`;
cropDiv.style.width = `${x2-x1}px`;
cropDiv.style.height = `${y2-y1}px`;
cropDiv.style.left = `${x1}px`;
cropDiv.style.top = `${y1}px`;
}
setCropRegion(10, 10, 240, 240);
* {
margin:0px;
}
.backgroundImg {
width:250px;
height:250px;
background-image: url('https://upload.wikimedia.org/wikipedia/en/e/ed/Nyan_cat_250px_frame.PNG');
position:relative;
}
.backgroundOverlay {
margin:0px;
padding:0px;
width:100%;
height:100%;
background-color:rgba(255,255,255,0.6);
}
.croppedRegion {
width:110px;
height:80px;
background-image: url('https://upload.wikimedia.org/wikipedia/en/e/ed/Nyan_cat_250px_frame.PNG');
background-size:250px 250px;
background-position:-80px -90px;
position:absolute;
top:90px;
left:80px;
}
<div class="backgroundImg">
<div class="backgroundOverlay">
<div class="croppedRegion"></div>
</div>
</div>