【问题标题】:Animate content div 'height' to 'Auto' onclick - jQuery动画内容 div 'height' 到 'Auto' onclick - jQuery
【发布时间】:2013-04-04 07:06:14
【问题描述】:

我有一个内容 div,我想将其设置为特定高度 (50px),然后单击更改为“自动”- 我可以使用 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)

【问题讨论】:

标签: jquery-animate jquery


【解决方案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/

【讨论】:

  • 感谢@ryanbrill,这很快!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-25
  • 2011-05-25
  • 2023-03-09
  • 1970-01-01
  • 2016-05-04
相关资源
最近更新 更多