一个简洁的、黑色风格的JS折叠层,点击展开、关闭层效果。以前在烈火下载栏目提供,可能有的同学没有发现,现在将它发到网页特效栏目,层默认情况下是展开的,点击后收缩,请根据自己的情况修改吧。 示例: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>JS+CSS完成的提示层效果</title> <style> * { margin:0; padding:0;} body { text-align:center; font:75% Verdana, Arial, Helvetica, sans-serif;} h1 { font:125% Arial, Helvetica, sans-serif; text-align:left; font-weight:bolder; background:#333; padding:3px; display:block; color:#99CC00} .class1 { width:40%; background:#CCC; position:relative; margin:0 auto; padding:5px;} span { position:absolute; right:10px; top:8px; cursor:pointer; color:yellow;} p { text-align:left; line-height:20px; background:#333; padding:3px; margin-top:5px; color:#99CC00} #class1content { height:300px;overflow:hidden} </style> <script> function $(element){ return element = document.getElementById(element); } function $D(){ var d=$('class1content'); var h=d.offsetHeight; var maxh=300; function dmove(){ h+=50; //设置层展开的速度 if(h>=maxh){ d.style.height='300px'; clearInterval(iIntervalId); }else{ d.style.display='block'; d.style.height=h+'px'; } } iIntervalId=setInterval(dmove,2); } function $D2(){ var d=$('class1content'); var h=d.offsetHeight; var maxh=300; function dmove(){ h-=50;//设置层收缩的速度 if(h<=0){ d.style.display='none'; clearInterval(iIntervalId); }else{ d.style.height=h+'px'; } } iIntervalId=setInterval(dmove,2); } function $use(){ var d=$('class1content'); var sb=$('stateBut'); if(d.style.display=='none'){ $D(); sb.innerHTML='展开'; }else{ $D2(); sb.innerHTML='收缩'; } } </script> </head> <body> <div class="class1"> <h1><a href="http://www.veryhuo.com/down">烈火下载</a></h1> <span id="stateBut" onclick="$use()">展开</span> <p id="class1content">困了的时候,睡觉最美。饿了的时候,吃饭最美。孤独的时候,想念最美。寂寞的时候,有人陪伴最美。喜悦的时候,分享最美。烦恼的时候,倾诉最美。<br> 小草和茉莉6051:记住自己要做一株风吹雨打永不倒的小草 不要被困难打败 不要被自己打败 不能再懦弱 要勇敢 坚强 自己要做一株拥有生生不息韧性的小草 坚持住 等待风雪后的春天。 </p> </div> </body> </html><div style="text-align:center;margin:30px 0 0 0;"><hr style="color:#999;height:1px;">如不能显示效果,请按Ctrl+F5刷新本页,更多网页代码:<a href='http://www.veryhuo.com/' target='_blank'>http://www.veryhuo.com/</a></div>提示:可修改后代码再运行! 文章导航 jQuery实现鼠标滑过打开层,文字展开效果jQuery点击按钮后弹出遮罩层,有关闭按钮