I'm trying to create a smooth transition for a div that's placed elsewhere when @media only screen and (max-width: #)
changes. The idea is when the max-width reaches, let's say, 600 pixels, the div smoothly transitions to another position.
Here's the fiddle: https://jsfiddle.net/8nQ6v/399/
This is a similar fiddle, transition is controlled by a click on the button: http://jsfiddle.net/8nQ6v/2/
HTML
<div id="square" class="position">
CSS
#square {
height: 100px;
width: 100px;
background-color: red;
}
.position {
position: absolute;
bottom: 20px;
left: 20px;
}
@media only screen and (max-width: 600px){
.position {
position: static!important;
}
}
With the current HTML & CSS it instantly hops to the other position. I'm wondering if there is someway to smoothly transition this.
The transition-timing-function property can have the following values: ease - specifies a transition effect with a slow start, then fast, then end slowly (this is default) linear - specifies a transition effect with the same speed from start to end. ease-in - specifies a transition effect with a slow start.
Using media queries. Media queries are commonly associated with CSS, but they can be used in HTML and JavaScript as well. There are a few ways we can use media queries directly in HTML.
The transition-delay property specifies when the transition effect will start. The transition-delay value is defined in seconds (s) or milliseconds (ms).
CSS transitions are generally best for simple from-to movements, while CSS animations are for more complex series of movements. It's easy to confuse CSS transitions and animations because they let you do similar things. Here are just a few examples: You can visualize property changes.
you can use css transition to animate
transition: ease all .5s;
and to animate don't change the position try changing the values
#square {
height: 100px;
width: 100px;
background-color: red;
transition: ease all .5s;
}
.position {
position: absolute;
bottom: 20px;
left: 300px;
}
@media only screen and (max-width: 600px) {
.position {
bottom: 20px;
left: 20px;
}
}
<div id="square" class="position">
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With