代码质量很低,希望老鸟能够指点指点。
下图是效果展示,能够借由jQuery的函数展开收缩
复制代码 代码如下:
//author: hlhr
//require: Jquery1.4 and above
function animate_toggle_height(maxh,minh,maxo,mino,element,speed) {//这个是纵向的,参数解释:最大高度,最小高度,最大透明度,最小透明度,元素,动画速度
if (element.css("height")==minh.toString().concat("px")){//如果是最小高度就展开
element.animate({
height:maxh,
opacity:maxo
},{queue: false},speed);
return "Fold"
}
if (element.css("height")==maxh.toString().concat("px")){//如果是最大高度就折叠
$(this).html("");
element.animate({
height:minh,
opacity:mino
},{queue: false},speed);
return "Read more";
}
}
function animate_toggle_width(maxw,minw,maxo,mino,element,speed) {
if (element.css("width")==minw.toString().concat("px")){
element.animate({
width:maxw,
opacity:maxo
},{queue: false},speed);
return "Fold"
}
if (element.css("width")==maxw.toString().concat("px")){
element.animate({
width:minw,
opacity:mino
},{queue: false},speed);
return "Read more";
}
}
复制代码 代码如下:
body{margin: 0 auto; text-align:center;}
.slide{font-size:20px; overflow: hidden; width: 500px; }
#content{margin:0 auto; width: 500px;}
.viewbutton{position:relative; text-align: right;}
viewbutton的层级可自行修改,但要注意动画的目标是什么。我写的viewbutton会对它上一级的那个div做动画,所以就不用把选择器写得过于复杂了。



