I have got this:
$('#btn-adm2').on('mouseover', function (event) {
$('#btn-adm2 .menu-text').css('height', '100%');
});
$('#btn-adm2').on('mouseout', function (event) {
$('#btn-adm2 .menu-text').css('height', '');
});
.menu-btn {
width: 100px;
height: 100px;
position: relative;
margin: auto;
overflow: hidden;
border-radius: 20px;
border: 3px solid White;
background-color: rgb(220, 220, 220);
box-sizing: border-box;
box-shadow: 10px 10px 40px rgba(0, 0, 0, 0.2);
transition: all 100ms linear;
}
.menu-btn:hover {
background-color: white;
border: 3px solid #0089c8;
/* Azul Ascendi */
transition: border 0.75s ease-in-out;
}
.menu-btn:hover .menu-text {
background-color: rgba(255, 255, 255, .8);
color: black;
transition: all 250ms linear;
}
.menu-item-div-top {
width: 25%;
height: 50%;
box-sizing: border-box;
display: inline-block;
}
.menu-text {
color: white;
font-size: 1.8vw;
line-height: 4vw;
position: absolute;
width: 100%;
text-align: center;
transition: all 100ms linear;
bottom: 0;
border-bottom-left-radius: 20px;
border-bottom-right-radius: 20px;
background-color: rgba(0, 0, 0, 0.5);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="menu-item-div-top"> <a href="#" onclick="underConstruction()">
<div id="btn-adm2" class="menu-btn" style="background-image: url('http://icons.iconarchive.com/icons/mazenl77/I-like-buttons-3a/512/Cute-Ball-Go-icon.png'); background-size: cover;">
<span class="menu-text">Press</span>
</div>
</a>
</div>
On hover, the height of the text div becomes 100%. I want it to grow with some animation instead of just turning into a full height div. I'm looking for the div to expand its height until the top of the button but I don't know how. Any help?
You are trying to add a transition for height 100%
. That is a little tricky for some browsers. Instead, try using the transition on max-height
. Transitions on max-height
usually is a much better way of using transitions.
You'll have to modify the code as below:
Add height
and set a value as max-height
to menu-text properties. I have set it to 25px in this example:
.menu-text {
color: white;
font-size: 1.8vw;
line-height: 4vw;
position: absolute;
width: 100%;
text-align: center;
transition: all 100ms linear;
bottom: 0;
border-bottom-left-radius: 20px;
border-bottom-right-radius: 20px;
background-color: rgba(0, 0, 0, 0.5);
height:100%;
max-height:25px;
}
and change the max-height
value on mouseover and mouseout events as below:
$('#btn-adm2').on('mouseover', function (event) {
$('#btn-adm2 .menu-text').css('max-height', '100%');
});
$('#btn-adm2').on('mouseout', function (event) {
$('#btn-adm2 .menu-text').css('max-height', '25px');
});
See this here -> http://jsfiddle.net/09ov6gn4/
Hope this helps!!!
You can use jQuery animate as well:
$('#btn-adm2').on('mouseover', function (event) {
$("#btn-adm2 .menu-text").animate({height:"100%"}, 10);
});
$('#btn-adm2').on('mouseout', function (event) {
$("#btn-adm2 .menu-text").animate({height:"25px"}, 10);
});
http://jsfiddle.net/o6hz9tra/
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