1
I’m trying to make a bar with text and image appear when clicking a button (as if it were a notification), this bar will grow until it reaches maximum size and revealing the content, but while the animation happens the text will be re-readpositioning, I would like it to stand still in its position and only the bar to move.
<!DOCTYPE html>
<html>
<head>
<style>
.notificacao {
width: 0px;
height: 100px;
background: whitesmoke;
display: flex;
overflow: hidden;
-webkit-transition: width 2s;
transition: width 2s;
}
.show {
width: 450px;
}
.avatar img {
width: 70px;
height: 70px;
margin: 20px;
}
.text {
margin: 5px 20px;
}
</style>
</head>
<body>
<div class="notificacao">
<div class="avatar">
<img src="https://cdn.icon-icons.com/icons2/1147/PNG/512/1486486303-alert-bell-notification-education-christmas-bell-church-bell-ring_81235.png">
</div>
<div class="text">
<p><strong>Chamando Notificação</strong></p>
<p>Recebeu uma notificação de determinada pessoa - <strong>NOME DA PESSOA</strong></p>
</div>
</div>
<br><br>
<button>Notificação</button>
<script type="text/javascript">
let notificacao = document.querySelector('.notificacao');
document.querySelector('button').addEventListener('click', function(){
notificacao.classList.add('show');
});
</script>
</body>
</html>
I tried to add the white-space property: nowrap.
.text {
white-space: nowrap;
margin: 5px 20px;
}
It even works as I wanted to keep the text still, but if it is too big (larger than the width of the bar) it will be hidden by the overflow:Hidden property.
<!DOCTYPE html>
<html>
<head>
<style>
.notificacao {
width: 0px;
height: 100px;
background: whitesmoke;
display: flex;
overflow: hidden;
-webkit-transition: width 2s;
transition: width 2s;
}
.show {
width: 450px;
}
.avatar img {
width: 70px;
height: 70px;
margin: 20px;
}
.text {
white-space: nowrap;
margin: 5px 20px;
}
</style>
</head>
<body>
<div class="notificacao">
<div class="avatar">
<img src="https://cdn.icon-icons.com/icons2/1147/PNG/512/1486486303-alert-bell-notification-education-christmas-bell-church-bell-ring_81235.png">
</div>
<div class="text">
<p><strong>Chamando Notificação</strong></p>
<p>Recebeu uma notificação de determinada pessoa - <strong>NOME DA PESSOA</strong></p>
</div>
</div>
<br><br>
<button>Notificação</button>
<script type="text/javascript">
let notificacao = document.querySelector('.notificacao');
document.querySelector('button').addEventListener('click', function(){
notificacao.classList.add('show');
});
</script>
</body>
</html>
Someone knows how to help me solve this?
I wanted to know JS to give you a straight answer, but just vc make a Settimeout with the same duration of your animation and then you remove the
white-space: nowrap;
class . text– hugocsl
I made an option just adding an extra class in the "component" to break the line at the end of the animation.
– hugocsl