搜索
首页web前端html教程CSDN的隐藏侧边栏功能是怎么实现的?_html/css_WEB-ITnose

 比如这个页面的“隐藏侧边栏”
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
从文本到网站:HTML的力量从文本到网站:HTML的力量Apr 13, 2025 am 12:07 AM

HTML是一种用于构建网页的语言,通过标签和属性定义网页结构和内容。1)HTML通过标签组织文档结构,如、。2)浏览器解析HTML构建DOM并渲染网页。3)HTML5的新特性如、、增强了多媒体功能。4)常见错误包括标签未闭合和属性值未加引号。5)优化建议包括使用语义化标签和减少文件大小。

了解HTML,CSS和JavaScript:初学者指南了解HTML,CSS和JavaScript:初学者指南Apr 12, 2025 am 12:02 AM

WebDevelovermentReliesonHtml,CSS和JavaScript:1)HTMLStructuresContent,2)CSSStyleSIT和3)JavaScriptAddSstractivity,形成thebasisofmodernWebemodernWebExexperiences。

HTML的角色:构建Web内容HTML的角色:构建Web内容Apr 11, 2025 am 12:12 AM

HTML的作用是通过标签和属性定义网页的结构和内容。1.HTML通过到、等标签组织内容,使其易于阅读和理解。2.使用语义化标签如、等增强可访问性和SEO。3.优化HTML代码可以提高网页加载速度和用户体验。

HTML和代码:仔细观察术语HTML和代码:仔细观察术语Apr 10, 2025 am 09:28 AM

htmlisaspecifictypefodyfocusedonstructuringwebcontent,而“代码” badlyLyCludEslanguagesLikeLikejavascriptandPytyPythonForFunctionality.1)htmldefineswebpagertuctureduseTags.2)“代码”代码“ code” code code code codeSpassSesseseseseseseseAwiderRangeLangeLangeforLageforLogageforLogicIctInterract

HTML,CSS和JavaScript:Web开发人员的基本工具HTML,CSS和JavaScript:Web开发人员的基本工具Apr 09, 2025 am 12:12 AM

HTML、CSS和JavaScript是Web开发的三大支柱。1.HTML定义网页结构,使用标签如、等。2.CSS控制网页样式,使用选择器和属性如color、font-size等。3.JavaScript实现动态效果和交互,通过事件监听和DOM操作。

HTML,CSS和JavaScript的角色:核心职责HTML,CSS和JavaScript的角色:核心职责Apr 08, 2025 pm 07:05 PM

HTML定义网页结构,CSS负责样式和布局,JavaScript赋予动态交互。三者在网页开发中各司其职,共同构建丰富多彩的网站。

HTML容易为初学者学习吗?HTML容易为初学者学习吗?Apr 07, 2025 am 12:11 AM

HTML适合初学者学习,因为它简单易学且能快速看到成果。1)HTML的学习曲线平缓,易于上手。2)只需掌握基本标签即可开始创建网页。3)灵活性高,可与CSS和JavaScript结合使用。4)丰富的学习资源和现代工具支持学习过程。

HTML中起始标签的示例是什么?HTML中起始标签的示例是什么?Apr 06, 2025 am 12:04 AM

AnexampleOfAstartingTaginHtmlis,beginSaparagraph.startingTagSareEssentialInhtmlastheyInitiateEllements,defiteTheeTheErtypes,andarecrucialforsstructuringwebpages wepages webpages andConstructingthedom。

See all articles

热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.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
4 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

mPDF

mPDF

mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。