Change div height smoothly

I have it:

$('#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>
Run code

When you hover, the height of the text becomes 100%. I want it to evolve with some animation instead of just turning into a full height div. I am looking for a div to increase its height to the top of the button, but I do not know how to do this. Any help?

+4
source share
5 answers

You are trying to add a transition for height 100%. For some browsers, this is a bit complicated. Instead, try switching to max-height. Transitions to max-heightare usually a much better way to use transitions.

You will need to change the code as shown below:

height max-height -. 25px :

.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;
}

max-height mouseover mouseout, :

$('#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');
});

http://jsfiddle.net/09ov6gn4/

, !!!

+1

jQuery:

$('#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/

+2

$('#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);
});
.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);
}
#btn-adm2 .menu-text{
 transition-duration: 2s;
}
<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>
0

.menu-text , , height: auto, css.

(: http://jsfiddle.net/o6hz9tra/2/)

.menu-text { height: 20px; }

: , (. : http://jsfiddle.net/leaverou/zwvNY/)

.menu-text {
    max-height:1.2em;
    background:slategray;
    color:white;

    -moz-transition: 1s;
    -ms-transition: 1s;
    -o-transition: 1s;
    -webkit-transition: 1s;
    transition: 1s;
}

.menu-text:hover {
    max-height:999px;
}
0
source

To use only CSS, you must translate the property min-height:

.menu-btn:hover .menu-text {
    background-color: rgba(255, 255, 255, .8);
    color: black;
    min-height: 100%;
    transition: all 250ms linear;
}

-DEMO -

As a note: you should avoid using transition: alland instead indicate which properties to transition to.

0
source

Source: https://habr.com/ru/post/1569562/


All Articles