Jitender
Jitender

Reputation: 7969

how to make animation work everytime in css3

I have made tab using css3 with some animation. The animation is working fine on first time when you click on tab but it is not working when you click the same tab again and also animation is not wokring even first time in chrome. fiddle

//Css

body {font-size:14px}
p{ margin:0; padding:0}
input[type=radio]{ display:none}
section[id^=tab]{ display:none}
section{border:1px solid #CCCCCC; width:650px; padding:10px; position:absolute; top:35px}
section p {-webkit-animation: growUp 0.4s ;}
label{border:1px solid #CCCCCC; float:left; border-bottom:none; padding:5px 15px; position:relative; margin-left:-1px; left:1px; cursor:pointer; background:#EEEEEE; z-index:-1} 
input[type=radio][id=tb1]:checked~section#tab-1{ display:block}
input[type=radio][id=tb1]:checked~label[for=tb1]{ background:#fff; z-index:1}
input[type=radio][id=tb2]:checked~section#tab-2{ display:block}
input[type=radio][id=tb2]:checked~label[for=tb2]{ background:#fff; z-index:1}
input[type=radio][id=tb3]:checked~section#tab-3{ display:block}
input[type=radio][id=tb3]:checked~label[for=tb3]{ background:#fff; z-index:1}
input[type=radio][id=tb4]:checked~section#tab-4{ display:block}
input[type=radio][id=tb4]:checked~label[for=tb4]{ background:#fff; z-index:1}
@keyframes growUp {
  0%   { transform:scale(0); -webkit-transform:scale(0); }
  100% { transform:scale(1); -webkit-transform:scale(1); }
}

//HTML

<div class="fl">
    <input type="radio" name="tab" id="tb1" checked="checked" />
    <label for="tb1">Tab1</label>
    <section id="tab-1"><p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</p></section>
</div>
<div class="fl">
    <input type="radio" name="tab" id="tb2" />
    <label for="tb2">Tab2</label>
    <section id="tab-2">
        <p>
            It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
        </p>
    </section>
</div>
<div class="fl">
    <input type="radio" name="tab" id="tb3" />
    <label for="tb3">Tab3</label>
    <section id="tab-3">
        <p>
            "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
        </p>
    </section>
</div>
<div class="fl">
    <input type="radio" name="tab" id="tb4" />
    <label for="tb4">Tab4</label>
    <section id="tab-4">
        <p>
            There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form 
        </p>
    </section>
</div>

Upvotes: 0

Views: 100

Answers (1)

Laxmikant Dange
Laxmikant Dange

Reputation: 7698

You have to use -webkit- prefix for css3 animation if you want to use it on webkit engine browsers like safari or chrome,

for example

@-webkit-keyframes growUp
/* Safari and Chrome */
 {
    0% {
        transform:scale(0);
        -webkit-transform:scale(0);
    }
    100% {
        transform:scale(1);
        -webkit-transform:scale(1);
    }
}

Here is your solution fiddle

Upvotes: 1

Related Questions