简体   繁体   中英

CSS Transitions

I have created the jQuery Script below, But am having a few problems converting it to preferably only CSS using transitions. If anybody could help me, I'll be greatfull.

Explanation of the example below:
- When you click on the text box a empty div container drops down, but I am having a few problems with scripting it in just mainly CSS3 Transitions.

HTML:

<div class="div">
    <input type="text" class="textbox" id="textbox"/>
    <p>example</p>
</div>

CSS:

.textbox {width:300px;}
.div { width:300px; background-color:#f8f8f8; }
p {width:300px; height:300px; background-color: #f8f8f8;}

jQuery:

$("#textbox").click(function() {
    $("p").slideToggle();
});

Live demo: jsFiddle

p {
    height: 0;
    overflow: hidden;
    transition: height .3s;
}
input:focus + p {
    height: 20px;
}

Here's your fiddle: http://jsfiddle.net/58VHE/33/ (click to focus on the input ).


PS Don't forget the vendor prefixes. The fiddle uses -prefix-free to auto-add the vendor prefixes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM