动画内容div'高度'为'自动'onclick - jQuery

时间:2013-04-11 22:09:51

标签: jquery-animate jquery

我有一个内容div,我希望将其设置为特定高度(50px),然后点击更改为'auto' - 我可以用jQuery做这个吗?我在YUI中看到它,见下面的代码

 function toggleContent(p, showFull) {
    if (showFull) {
        YAHOO.util.Dom.setStyle(p, 'height', 'auto');
        p.setAttribute('onclick', "toggleContent(this, false);")
    } else {
        YAHOO.util.Dom.setStyle(p, 'height', '50px');
        p.setAttribute('onclick', "toggleContent(this, true);")
    }
    }

Here is an example of I want (YUI)

1 个答案:

答案 0 :(得分:1)

这是使用jQuery更新的代码:

function toggleContent(p, showFull) {
    if (showFull) {
        $(p).height('auto');
        p.setAttribute('onclick', "toggleContent(this, false);")
    } else {
        $(p).height('50px');
        p.setAttribute('onclick', "toggleContent(this, true);")
    }
}

http://jsfiddle.net/ryanbrill/XUSdC/1/

相关问题