Animate text alignment using jquery

前端 未结 1 1866
天涯浪人
天涯浪人 2020-12-21 19:45

At the click of a button $(\'#btn\').click(), I want a group of span elements be set with CSS text-align right (originally text-aligned left) and m

相关标签:
1条回答
  • 2020-12-21 20:09

    HTML markup (no change)

    <div id="main" style="width: 300px;">
        <div class="item">
            <span class="info">Strings</span>
        </div>
        <div class="item">
            <span class="info">Strings</span>
        </div>
    </div>
    

    CSS markup

    .info {
        display: block;   /* width works better on block level elements */
        text-align: right;
        width: 20%;       /* use something sensible as the default value */
        overflow: hidden; /* if you choose 0% for the above property then use this */
    }
    

    jQuery code

    $(document).ready(function() {
        $(".info").animate({
            width: "100%"
        }, 1000);
    });
    

    Demo here

    PS: I'd rather use CSS position relative+absolute along with CSS overflow+left properties.

    0 讨论(0)
提交回复
热议问题