Аналогичный ответ на тот, который предоставлен Temani Afif, но с использованием svg вместо изображения (поэтому нет необходимости в дополнительном запросе).
Кроме того, легче адаптировать его к произвольным пропорциям
.container {
height: 150px;
background-color: lightblue;
display: flex;
align-items: center;
justify-content: center;
margin: 10px;
}
.aspectRatio {
display: grid;
background-color: yellow;
height: 50%;
}
.aspectRatio svg {
height: 100%;
border: solid 1px red;
animation: resize 1s infinite;
}
.aspectRatio > * {
grid-area: 1 / 1 / 2 / 2;
}
@keyframes resize {
from {height: 100%;}
to {height: 99.9%;}
}
<div class="container">
<div class="aspectRatio">
<svg viewBox="0 0 1 1"></svg>
<div class="inner">square</div>
</div>
</div>
<div class="container">
<div class="aspectRatio">
<svg viewBox="0 0 4 3"></svg>
<div class="inner">ratio 4/3</div>
</div>
</div>
Код Я закончил использование после некоторой инструкции из комментариев.
var delInterval = setInterval(del(), 1000);
function del(){
fs.open(filePath, 'r+', function(err, fd){
if (err && err.code === 'EBUSY'){
//do nothing till next loop
} else if (err && err.code === 'ENOENT'){
console.log(filePath, 'deleted');
clearInterval(delInterval);
} else {
fs.close(fd, function(){
fs.unlink(filePath, function(err){
if(err){
} else {
console.log(filePath, 'deleted');
clearInterval(delInterval);
}
});
});
}
});
}