目錄
回复讨论(解决方案)
首頁 web前端 html教學 CSDN的隐藏侧边栏功能是怎么实现的?_html/css_WEB-ITnose

CSDN的隐藏侧边栏功能是怎么实现的?_html/css_WEB-ITnose

Jun 24, 2016 pm 12:18 PM

 比如这个页面的“隐藏侧边栏”
http://bbs.csdn.net/
给个源码看看


回复讨论(解决方案)

其实就是设置 css,显示style.display='block',隐藏style.display='node'
我写了个例子,与csdn的实现方式可能不一样

<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用的是frameset,设置其中framset的cols属性为0,*收缩导航,设置为230,*展开导航




我这样写为什么“隐藏”按钮不显示?

<!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>
登入後複製

我研究了各位老大的方法,结果死活只在IE里才好用,其它的遨游、谷歌之类的点击了都没有反应,代码如下:

<!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>
登入後複製

left_close.html文件在这里,和上面的放在一个目录里:

<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>
登入後複製


各位老大帮忙看看吧!拜托了!

这个也没有效果:

 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,*' }
登入後複製

、脚本写最简单吧,。。。

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
1 個月前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

&gt; gt;的目的是什麼 元素? &gt; gt;的目的是什麼 元素? Mar 21, 2025 pm 12:34 PM

本文討論了HTML&lt; Progress&gt;元素,其目的,樣式和與&lt; meter&gt;元素。主要重點是使用&lt; progress&gt;為了完成任務和LT;儀表&gt;對於stati

&lt; datalist&gt;的目的是什麼。 元素? &lt; datalist&gt;的目的是什麼。 元素? Mar 21, 2025 pm 12:33 PM

本文討論了html&lt; datalist&gt;元素,通過提供自動完整建議,改善用戶體驗並減少錯誤來增強表格。Character計數:159

HTML5中跨瀏覽器兼容性的最佳實踐是什麼? HTML5中跨瀏覽器兼容性的最佳實踐是什麼? Mar 17, 2025 pm 12:20 PM

文章討論了確保HTML5跨瀏覽器兼容性的最佳實踐,重點是特徵檢測,進行性增強和測試方法。

&lt; meter&gt;的目的是什麼。 元素? &lt; meter&gt;的目的是什麼。 元素? Mar 21, 2025 pm 12:35 PM

本文討論了HTML&lt; meter&gt;元素,用於在一個範圍內顯示標量或分數值及其在Web開發中的常見應用。它區分了&lt; meter&gt;從&lt; progress&gt;和前

如何使用HTML5表單驗證屬性來驗證用戶輸入? 如何使用HTML5表單驗證屬性來驗證用戶輸入? Mar 17, 2025 pm 12:27 PM

本文討論了使用HTML5表單驗證屬性,例如必需的,圖案,最小,最大和長度限制,以直接在瀏覽器中驗證用戶輸入。

視口元標籤是什麼?為什麼對響應式設計很重要? 視口元標籤是什麼?為什麼對響應式設計很重要? Mar 20, 2025 pm 05:56 PM

本文討論了視口元標籤,這對於移動設備上的響應式Web設計至關重要。它解釋瞭如何正確使用確保最佳的內容縮放和用戶交互,而濫用可能會導致設計和可訪問性問題。

&lt; iframe&gt;的目的是什麼。 標籤?使用時的安全考慮是什麼? &lt; iframe&gt;的目的是什麼。 標籤?使用時的安全考慮是什麼? Mar 20, 2025 pm 06:05 PM

本文討論了&lt; iframe&gt;將外部內容嵌入網頁,其常見用途,安全風險以及諸如對象標籤和API等替代方案的目的。

Gitee Pages靜態網站部署失敗:單個文件404錯誤如何排查和解決? Gitee Pages靜態網站部署失敗:單個文件404錯誤如何排查和解決? Apr 04, 2025 pm 11:54 PM

GiteePages靜態網站部署失敗:404錯誤排查與解決在使用Gitee...

See all articles