Javascript code controls the effect of web page layer collapse and expansion

From , 2 Years ago, written in JavaScript, viewed 130 times.
URL https://pastebin.vip/view/21c3134e
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3.   <head>
  4.     <base href="<%=basePath%>">
  5.      
  6.     <meta http-equiv="pragma" content="no-cache">
  7.     <meta http-equiv="cache-control" content="no-cache">
  8.     <meta http-equiv="expires" content="0">    
  9.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  10.     <meta http-equiv="description" content="This is my page">
  11.     <!--
  12.     <link rel="stylesheet" type="text/css" href="styles.css">
  13.     -->
  14.     <title>很酷的DIV层的展开收缩效果</title>
  15.         <style>
  16.         * { margin:0; padding:0;}
  17.         body { text-align:center; font:75% Verdana, Arial, Helvetica, sans-serif;}
  18.         h1 { font:125% Arial, Helvetica, sans-serif; text-align:left; font-weight:bolder; background:#333;  padding:3px; display:block; color:#99CC00}
  19.         .class1 { width:40%; background:#CCC; position:relative; margin:0 auto; padding:5px;}
  20.         span { position:absolute; right:10px; top:8px; cursor:pointer; color:yellow;}
  21.         p { text-align:left; line-height:20px; background:#333; padding:3px; margin-top:5px; color:#99CC00}
  22.         #class1content { height:300px;overflow:hidden}
  23.         </style>
  24.         <script>
  25.             function $(element){
  26.             return element = document.getElementById(element);
  27.             }
  28.             function $D(){
  29.             var d=$('class1content');
  30.             var h=d.offsetHeight;
  31.             var maxh=300;
  32.             function dmove(){
  33.             h+=50; //设置层展开的速度
  34.             if(h>=maxh){
  35.             d.style.height='300px';
  36.             clearInterval(iIntervalId);
  37.             }else{
  38.             d.style.display='block';
  39.             d.style.height=h+'px';
  40.             }
  41.             }
  42.             iIntervalId=setInterval(dmove,2);
  43.             }
  44.             function $D2(){
  45.             var d=$('class1content');
  46.             var h=d.offsetHeight;
  47.             var maxh=300;
  48.             function dmove(){
  49.             h-=50;//设置层收缩的速度
  50.             if(h<=0){
  51.             d.style.display='none';
  52.             clearInterval(iIntervalId);
  53.             }else{
  54.             d.style.height=h+'px';
  55.             }
  56.             }
  57.             iIntervalId=setInterval(dmove,2);
  58.             }
  59.             function $use(){
  60.             var d=$('class1content');
  61.             var sb=$('stateBut');
  62.             if(d.style.display=='none'){
  63.             $D();
  64.             sb.innerHTML='收缩';
  65.             }else{
  66.             $D2();
  67.             sb.innerHTML='展开';
  68.             }
  69.             }
  70.         </script>
  71.              
  72.           </head>
  73.    
  74.   <body>
  75.     <div class="class1">
  76.         <h1>DIV层的展开隐藏效果</h1>
  77.         <span id="stateBut" onclick="$use()">展开</span>
  78.         <p id="class1content">曾经有一份真诚的爱情放在我面前, <br>我没有珍惜,<br>等我失去的时候我才后悔莫及,<br>人世间最痛苦的事莫过于此。<br>如果上天能够给我一个再来一次的机会,<br>我会对那个女孩子说三个字:<br>我爱你。<br>如果非要在这份爱上加上一个期限,<br>我希望是……一万年!”
  79.        
  80.     </div>
  81.  
  82.   </body>
  83. </html>
  84. //javascript/6769

Reply to "Javascript code controls the effect of web page layer collapse and expansion"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website