Daniel
Daniel

Reputation: 388

CSS3 transition misunderstood

This should be a very simple straightful linear transition effect, but for somehow it's not working. Any idea why?

HTML

<div class="button-modern" style="background-color:#e73032">
    <span style="color:#fff; font-size:1rem">MORE</span>
    <br><span style="color:#fff; font-size:2rem">INFORMATION</span>

    <div class="button-modern--info">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</div>
    <div class="button-modern--click js-button-modern--click"> 
       <span></span>
    </div>
</div>

CSS

.button-modern {
    padding: 18px 22px;
    position: relative;
}
.button-modern--opened .button-modern--info {
    text-transform: none;
    height: 100%;
}
.button-modern--click {
    width: 56px;
    height: 56px;
    position: absolute;
    bottom: 0;
    right: 0;
    overflow: hidden;
}
.button-modern--click > span:before {
    font-family:'FontAwesome';
    font-weight: normal;
    font-style: normal;
    speak: none;
    vertical-align: middle;
    font-size: 26px;
    content:" \F107";
    padding: 0 10px 0 0;
    color: #fff;
    position: absolute;
    right: 0;
    bottom: 0;
}
.button-modern--opened .button-modern--click > span:before {
    font-family:'FontAwesome';
    font-weight: normal;
    font-style: normal;
    speak: none;
    vertical-align: middle;
    font-size: 26px;
    content:" \F106";
    padding: 0 10px 0 0;
    color: #fff;
    position: absolute;
    right: 0;
    bottom: 0;
}
.button-modern--click > span {
    cursor: pointer;
}
.button-modern--info {
    height: 0;
    overflow: hidden;
    -webkit-transition: all 200ms linear;
    -moz-transition: all 200ms linear;
    transition: all 200ms linear;
}

JS

$('.button-modern').find('.js-button-modern--click').click(function (e) {
    $(this).parent().toggleClass('button-modern--opened');
});

JSFiddle http://jsfiddle.net/zilli/7rpEW/

Upvotes: 2

Views: 235

Answers (1)

Josh Crozier
Josh Crozier

Reputation: 240858

The transition wasn't working because it isn't triggered when adding/removing a class, as it doesn't have anything to transition to/from.

$( ".button-modern--info" ).hide();
$( ".button-modern--click" ).click(function() {
    $(this).prev( ".button-modern--info" ).slideToggle( "slow" );
});

jsFiddle example

Basically, I used .hide() to hide it initially, and then .slideToggle was used to display it.

Upvotes: 1

Related Questions