1
I have an element with the position defined as "Fixed", when I apply the property "Transform" to create an animation the fixed element loses its position (when clicking the button to animate it becomes clearer).
How to fix this?
document.addEventListener("DOMContentLoaded", function(event) {
document.querySelector('button').onclick = () => {
const container = document.querySelector('.container');
container.style.transform = 'translateX(-100px)'
setTimeout(()=>{
container.style.transform = "";
}, 1100)
};
});
main{
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.container{
width: 320px;
height: 500px;
background-color: #717;
transition: all 1s;
}
.fixed{
position: fixed;
width: 320px;
height: 70px;
background: rgb(251, 255, 0);
top: 0px;
}
button{
margin: 15px;
}
<main>
<div class="container">
<div class="fixed"></div>
</div>
<button>Animate</button>
</main>
I can’t understand the mentality of these people who are negative, what’s the problem? if I didn’t know how to ask help me improve the question, don’t worry and run away, if you don’t understand the subject or will not contribute in any way to the problem, negative will not help at all.
– Null
Dude, I don’t get what you mean by "lose your position" what’s going on that you shouldn’t? And on the negative vote, don’t worry, there’s a user here who from Downvote on every new question, especially if I had the CSS tag. The guy thinks that with a Downvote he helps on something rss, rather vote negative than lose 1 min trying to help in fact
– hugocsl