Reputation: 39
I have tried this construction in several browsers, and it not working. Please help to find my mistake.
<style>
.result{
width: 200px;
height: 300px;
background: #ff0000;
}
.result #add{
display:none;
}
.result:hover #add{
-webkit-transition: top 1s ease-out 1.5s;
-moz-transition: top 1s ease-out 1.5s;
transition: top 1s ease-out 1.5s;
display:block;
}
</style>
<div class="result">
<div id="add">111</div>
</div>
Upvotes: 1
Views: 85
Reputation: 9567
A few things to clean up first
display: none
to display: block
. Just can't happen. I would recommend transitioning opacity: 0
to opacity: 1
instead for a fade-in effecttransition: top 1s ease-out 1.5s
call will only animate top attribute. That's what the top
means in that line. You can add multiple targets via a comma delimited list, e.g. top 1s ease-out, opacity 1s ease-out
etc. etc. Alternatively, you can just write the rule as transition: 1s ease-out
and it will animate all changes (but this may have some minor performance hits as opposed to selecting the attributes to animate). .result{
width: 200px;
height: 300px;
top: 0;
background: #ff0000;
}
.result #add{
opacity: 0;
position: relative;
}
.result:hover #add{
-webkit-transition: 1s ease-out 1.5s;
-moz-transition: 1s ease-out 1.5s;
transition: 1s ease-out 1.5s;
opacity: 1;
top: 40px;
}
And that, as written, should work for you.
Upvotes: 2
Reputation: 206161
3 issues:
top
property into your transition top 1s ease-out 1.5s;
but there's no top
to refer to.position
property for your #add
elementdisplay:block;
will trigger a fast redraw which will prevent the right CSS's calculations needed to apply the top transition - try with opacity
insteadHere's all applied to an example:
.result{
width: 200px;
height: 300px;
background: #ff0000;
}
.result #add{
opacity: 0;
position:relative;
top:0;
}
.result:hover #add{
opacity: 1;
-webkit-transition: top 1s ease-out 1.5s;
-moz-transition: top 1s ease-out 1.5s;
transition: top 1s ease-out 1.5s;
top:150px;
}
<div class="result">
<div id="add">111</div>
</div>
Upvotes: 1