Home >Web Front-end >HTML Tutorial >How is CSDN's hidden sidebar function implemented? _html/css_WEB-ITnose

How is CSDN's hidden sidebar function implemented? _html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:18:502003browse

For example, the "hide sidebar" of this page
http://bbs.csdn.net/
Show me the source code


Reply to the discussion (solution)

In fact, it is to set css, display style.display='block', hide style.display='node'
I wrote an example, which may be different from the csdn implementation

<style>  html,body{ width:100%;height:100%;padding:0px;margin:0px;overflow:hidden  }  #ifr1{height:100%;width:200px;float:left;  }  #ifr2{height:100%;width:100px float:right; }  #hand{    position: absolute;    z-index: 99;    left: 200px;    top: 48%;    height: 50px;    word-break: break-all;    display: block;    width: 20px;    background: #fff;    text-align: center;    border: 1px solid #ccf;  } </style> <iframe id="ifr1" src="http://bbs.csdn.net/left_menu"></iframe>  <iframe id="ifr2" src="http://bbs.csdn.net/home"></iframe>  <div id="hand" >隐藏</div>  <script> function $(id){return document.getElementById(id) } var w,hand=$('hand'),ifr1=$('ifr1'),ifr2=$('ifr2'); hand.onclick=function(){ //点击隐藏按钮  var sty=ifr1.style,disp;  sty.display=sty.display=='none'?'block':'none';  doResize(); } function doResize(){ //调整位置大小  var w=document.body.clientWidth;  var sty=ifr1.style,disp;  if(sty.display=='none'){    ifr2.style.width='100%';    hand.style.left='1px';  }else{    ifr2.style.width=w-220+'px';    hand.style.left='200px';  } } window.onload=window.onresize=doResize; doResize() </script>

csdn uses frameset, set the cols attribute of frameset to 0, *collapse navigation, set to 230, *expand navigation

3f37bd83bd440df50863013332c184be
e5dc80fe58ebad587381229c0c75f761
e72f99c72d4f4be183da6da775eb999a
eb5f059992a0ae0ef16884cb75644e40

Why do I write this "hide" "Button not showing?"

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>  <head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <title>左右布局侧边栏演示</title>        <link href="http://csdnimg.cn/www/images/favicon.ico" rel="SHORTCUT ICON"><style>  //html,body{ width:100%;height:100%;padding:0px;margin:0px;overflow:hidden  }  //#ifr1{height:100%;width:200px;float:left;  }  //#ifr2{height:100%;width:100px float:right; }  #hand{    position: absolute; // 绝对定位    z-index: 10001; // 优先级最高(离用户最近)    left: 200px;    top: 48%;    height: 50px;    word-break: break-all;    display: block;    width: 20px;    //background: #fff;    text-align: center;    border: 1px solid #ccf;  } </style>  </head>  <frameset cols="230,*" frameborder="no" border="0" framespacing="0">    <frame src="左右框架窗体1.html" name="leftFrame"  noresize="noresize" id="ifr1" title="leftFrame" />    <frame src="左右框架窗体1.html" name="mainFrame" id="ifr2" title="mainFrame" />  </frameset>  <noframes>    <div id="hand" >隐藏</div><script> function $(id){   return document.getElementById(id) } var w,hand=$('hand'),ifr1=$('ifr1'),ifr2=$('ifr2'); hand.onclick=function(){ //点击隐藏按钮  var sty=ifr1.style,disp;  sty.display=sty.display=='none'?'block':'none';  doResize(); } function doResize(){ //调整位置大小  var w=document.body.clientWidth;  var sty=ifr1.style,disp;  if(sty.display=='none'){    ifr2.style.width='100%';    hand.style.left='1px';  }else{    ifr2.style.width=w-220+'px';    hand.style.left='200px';  } } window.onload=window.onresize=doResize; doResize() </script>    <body>    </body>  </noframes></html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>  <head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <title>CSDN论坛首页 - CSDN.NET</title>    <script src="/assets/application-1a33bfd3d5ee7e433197442aeb9c03b6.js" type="text/javascript"></script>    <script type="text/javascript">      $(function() {        main_page_js.index_page();      });    </script>    <link href="http://csdnimg.cn/www/images/favicon.ico" rel="SHORTCUT ICON">  </head>  <frameset cols="230,*" frameborder="no" border="0" framespacing="0">    <frame src="/left_menu" name="leftFrame"  noresize="noresize" id="leftFrame" title="leftFrame" />    <frame src="/home" name="mainFrame" id="mainFrame" title="mainFrame" />  </frameset>  <noframes>    <body>    </body>  </noframes></html>

I studied everyone’s method, and it turns out that it only works in IE. Other apps like Aoyou, Google, etc. No response, the code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>  <head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <title>左右布局侧边栏演示</title>  </head><frameset rows="*" name="top_function" id="top_function" frameborder="NO" border="0" framespacing="0">  <frameset cols="20%,20,*" name="left_function" id="left_function" frameborder="NO" border="0" framespacing="0">    <frame src="left.html" name="leftFrame" id="leftFrame" title="leftFrame" /><frame src="left_close.html" name="left_close" id="left_close" scrolling="NO" noresize="noresize" title="left_close" style="border-color:#FF0000; border-style:solid; border-width:1px; padding-right:2" />    <frame src="right.html" name="mainFrame" id="mainFrame" title="mainFrame" />  </frameset></frameset>  <noframes>    <body><p>此网页使用了框架,但您的浏览器不支持框架。</p>    </body>  </noframes></html>

The left_close.html file is here, put it in the same directory as the above:

<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>关闭和显示侧边栏</title><SCRIPT LANGUAGE="javascript"><!--function shleft(){ if (parent.left_function.cols!="20%,20,*"){  parent.left_function.cols="20%,20,*" } else{  parent.left_function.cols="0,20,*" }}//--></SCRIPT></head><body onclick="shleft();"></body></html>


Everyone Boss, please help me! Please!

This also has no effect:

 if (parent.document.getElementById('top_function').rows!='10%,20,*'){  parent.document.getElementById('top_function').rows='10%,20,*' }else{  parent.document.getElementById('top_function').rows='0,20,*' }

, the script is the easiest to write. . .

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn