I am trying to make a progress indicator that looks like emptying a glass of beer. Unfortunately, I am not a very artistic person, but I am doing my best.
My concept is as follows:
- There is
<div>a background of "beer", 100% vertical. It hides any overflow - Inside there is another
<div>, located relative to the parent. It contains:- White background
<div>to hide the “beer” pattern when it is gone. - Image of beer foam cap
Here is the concept of the picture:

I almost succeeded in my goal, as you can see in this snippet:
Note: ES6 async / await is required for animation
Promise.timeout = function (delay) {
return new Promise((resolve) => {
setTimeout(resolve, delay);
});
};
Promise.animationFrame = function () {
return new Promise((resolve) => {
requestAnimationFrame(resolve);
});
};
(async function () {
const progress = document.querySelector("div.top");
for (let i = 0, l = 1000; i < l; ++i) {
progress.style.bottom = (100 - i / 10) + "%";
await Promise.animationFrame();
}
})();
html, body, div {
margin: 0px;
padding: 0px;
}
body {
width: 100vw;
height: 100vh;
overflow: hidden;
}
div.progress {
max-width:300px;
width: 100vw;
float: left;
position: relative;
overflow: hidden;
height: 100%;
background-image: url("https://i.imgur.com/SKfSqEv.jpg");
background-size: 500px;
border-right: 1px solid black;
}
div.progress div.top {
height: 100vh;
position: relative;
bottom: 100%;
}
div.progress div.top div.white{
background-color: white;
width:100%;
height:100%;
}
div.progress div.top div.beer-top {
background-repeat: repeat-x;
background-position-y: bottom;
background-position-x: left;
background-size: 302px, 100px;
height: 100px;
}
div.main {
float: left;
}
div.progress div.top div.beer-top {
background-image: url('https://preview.ibb.co/k2x2V6/beer_top.png');
}
<div class="progress">
<div class="top">
<div class="white"></div>
<div class="beer-top"></div>
</div>
</div>
<div class="main">
</div>
Run codeHide resultBut there are two big problems:
- :

div.white height 100%, "100%". . :

?
CSS, (, 40% javascript).
: " div" , .