CSS3 equivalent to jQuery slideUp and slideDown?

前端 未结 10 1122
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 08:12

My application is performing poorly with jQuery\'s slideDown and slideUp. I\'m looking to use a CSS3 equivalent in browsers which support it.

Is it possible, using C

10条回答
  •  借酒劲吻你
    2020-12-04 08:47

    Variant without JavaScript. Only CSS.

    CSS:

    .toggle_block {
        border: 1px solid #ccc;
        text-align: left;
        background: #fff;
        overflow: hidden;
    }
    .toggle_block .toggle_flag {
        display: block;
        width: 1px;
        height: 1px;
        position: absolute;
        z-index: 0;
        left: -1000px;
    }
    .toggle_block .toggle_key {
        font-size: 16px;
        padding: 10px;
        cursor: pointer;
        -webkit-transition: all 300ms ease;
           -moz-transition: all 300ms ease;
            -ms-transition: all 300ms ease;
             -o-transition: all 300ms ease;
                transition: all 300ms ease;
    }
    .toggle_block .content {
        padding: 0 10px;
        overflow: hidden;
        max-height: 0;
        -webkit-transition: all 300ms ease;
           -moz-transition: all 300ms ease;
            -ms-transition: all 300ms ease;
             -o-transition: all 300ms ease;
                transition: all 300ms ease;
    }
    .toggle_block .content .toggle_close {
        cursor: pointer;
        font-size: 12px;
    }
    .toggle_block .toggle_flag:checked ~ .toggle_key {
        background: #dfd;
    }
    .toggle_block .toggle_flag:checked ~ .content {
        max-height: 1000px;
        padding: 10px 10px;
    }
    

    HTML:

    Text 1
    Text 2

    For next block only change ID and FOR attributes in html.

提交回复
热议问题