这确实增加jQueryUI的的要求,以获得动画但是它的工作原理完全
第一你的CSS改变
.category_text {
float: left;
position: relative;
overflow: hidden;
margin-bottom: 1em;
max-height: 120px;
}
.cat-height {
max-height: 9999px;
padding-bottom:30px;
}
然后改变你的JavaScript使用toggleClass像这样
$(document).ready(function() {
$(".showbutton").live("click", function (e) {
e.preventDefault();
var buttonid = $(this).attr("id");
buttonid = buttonid.substring(11, buttonid.length);
$("#text_"+buttonid).toggleClass('cat-height','slow');
if($("#showbutton_" + buttonid).text() == 'Show') {
$("#showbutton_" + buttonid).text("Hide");
}
else {
$("#showbutton_" + buttonid).text("Show");
}
return false;
});
});
DEMO
这很好用,t无论出于何种原因,jQueryUI添加到我们网站的页脚(或者至少在添加此脚本的位置之下)......是否有使用jQuerys延迟或其他方法获得相同效果的方法? – Jarede
@Jarede在旁边注释如果你不想使用JQueryUI,你可以利用CSS3转换并依赖标准的JQuery toggleClass – AbstractChaos