Alex
Alex

Reputation: 2062

jQuery - Text is unseen while being animated

I'm trying to create a dynamic meter which fills according to some input. Above the meter there's a text and a divider, which move as the meter changes. This works almost perfect, the only thing that I cant figure out is that the divider and text are unseen while being animated, and sort of pop up upon animation end. How can this be fixed?

JSfiddle here;

HTML:

<div id="meterContainer" class="meterGeneralStyling">
    <div id="meter" class="meterGeneralStyling"> <span id="reachSpan">ddd</span><span id="testDivider"></span>

    </div>
</div>
<button id="butt">move</button>

JS:

$("#meter").css("width","15%");   //initial value

function resizeReach(width){
            $("#meter").animate({
                width: ""+width+"%"
            }, 1500);
    }

$("#butt").click(function(){

    resizeReach(Math.floor(Math.random() * 90) + 10 );
});

CSS:

.meterGeneralStyling{
    position: relative;
}

#row2{
    top: 30px;
}
#meterContainer{
    position: relative;
    top: 100px;
    height: 10px;
    z-index: -2;
    background-color: #abddff;
    overflow: visible !important;
}
#meter{
    height: 10px;
    background-color: #48B0F7;
    position: absolute;
    bottom: 0;

}

#reachSpan{
    position: absolute;
    right: 0;
    bottom: 10px;

}

#testDivider{
    z-index: 3;
    position: absolute;
    height: 30px;
    border-left: 3px solid red;
    right: 0;
    bottom: 0px;
}

Upvotes: 0

Views: 72

Answers (2)

Cosmin
Cosmin

Reputation: 1490

You should also have visible for the .meterGeneralStyling

.meterGeneralStyling{
    position: relative;
    overflow: visible !important;
}

Upvotes: 0

Hackerman
Hackerman

Reputation: 12295

Just add overflow: visible !important; to #meter

#meter{
   height: 10px;
   background-color: #48B0F7;
   position: absolute;
   bottom: 0;
   overflow: visible !important;
}

Upvotes: 1

Related Questions