Home > Web Front-end > HTML Tutorial > How to achieve the sliding door effect with CSS_html/css_WEB-ITnose

How to achieve the sliding door effect with CSS_html/css_WEB-ITnose

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-24 11:41:17
Original
1333 people have browsed it

How to implement the sliding door effect with CSS:
The so-called sliding door and tab tab actually mean the same thing. Here is an example of how to implement this function, the code The example is as follows:

<!DOCTYPE html>   <html>   <head>   <meta charset=" utf-8">   <meta name="author" content="http://www.51texiao.cn/" /> <meta name="keywords" content="JS实现的新闻列表tab选项卡效果、JS特效、Jquery特效" /><meta name="description" content="JS实现的新闻列表tab选项卡效果、JS特效、Jquery特效" /><title>JS实现的新闻列表tab选项卡效果-蚂蚁部落</title><style type="text/css">* {  padding:0;  margin:0}img {  border:0;  display:block;}body {  font-size:12px;  margin:0px auto;  color:black;  text-align:center;}.dis{  display:block;}.undis {  display:none;}#cntR {  width:302px;  margin:0 auto;}#NewsTop{  clear:both;  margin-bottom:16px;}#NewsTop P {  float:left;  line-height:21px}#NewsTop P.topTit {  font-weight:bold;  width:117px;}#NewsTop P.topC0 {  background:#dcdcdc;  border-left:#f2f2f2 1px solid;  width:40px;  cursor:pointer}#NewsTop P.topC1 {  background:#c2130e;  border-left:#f2f2f2 1px solid;  width:40px;  color:#fff}#NewsTop #NewsTop_tit{  border-bottom:#c2130e 3px solid;  height:21px;}#NewsTop #NewsTop_cnt{  padding-left:32px;  line-height:26px;  padding-top:7px;  height:260px;  text-align:left;}#NewsTop #NewsTop_cnt a {  color:#666;  text-decoration:none}#NewsTop #NewsTop_cnt a:hover {  color:#c2130e;  text-decoration:underline}</style></head><body><div id="cntR">  <div id="NewsTop">    <div id="NewsTop_tit">      <P class="topTit">新闻排行</P>      <P class="topC0">国内</P>      <P class="topC0">国际</P>      <P class="topC0">社会</P>      <P class="topC0">网评</P>    </div>    <div id="NewsTop_cnt">     <span title="Don't delete me"></span>     <span>       <a href="#">新疆阜康铁路桥梁坍塌多节运煤车厢侧翻坠河</a><br/>      <a href="#">最高法:承诺不判赖昌星死刑没有超越法律程序</a><br/>      <a href="#">物权法:满70年住宅建设用地使用权将自动续期</a><br/>      <a href="#">弟弟被妻下药毒死男子买女尸为其配阴婚(图)</a><br/>      <a href="#">揭开郑州神枪手神秘面纱 头号狙击手是近视眼</a><br/>      <a href="#">美军高官:不排除和中国发生直接军事对抗可能</a><br/>      <a href="#">浙江东阳传奇富姐吴英涉嫌非法吸收存款被批捕</a><br/>      <a href="#">西方炒作"中国航母威胁论"称05年已正式服役</a><br/>      <a href="#">女孩生活无法自理请人大代表递交安乐死议案</a><br/>      <a href="#">建设部:住房公积金制度将覆盖农民工</a><br/>      <div align="right"><a href="#">...more</a></div>    </span>     <span>       <a href="#">美华裔女兵在营房上吊死亡军方介入调查(图)</a><br/>      <a href="#">组图:美国总统布什车队被撞</a><br/>      <a href="#">梦露掌握肯尼迪之弟秘密遭诱骗自杀(组图)</a><br/>      <a href="#">孟加拉国严打贪官人人自危奔驰宝马抛弃路边</a><br/>      <a href="#">韩国将举行大规模军事演习(图文)</a><br/>      <a href="#">组图:土星最大卫星表面发现“海洋”</a><br/>      <a href="#">墨西哥缉毒行动缴获2亿美元巨额现钞(组图)</a><br/>      <a href="#">组图:全球掀起裸体抗议加拿大捕猎海豹活动</a><br/>      <a href="#">美潜艇在百慕大失踪一晚航母战群出动搜索</a><br/>      <a href="#">匈牙利20万人示威 政要被民众扔鸡蛋(组图)</a><br/>      <div align="right"><a href="#">...more</a></div>    </span>     <span>       <a href="#">深圳女工被三名男子轮奸男友目睹过程(组图)</a><br/>      <a href="#">男子珍藏一角钱“币王”价格高达1.3万(图)</a><br/>      <a href="#">青海女孩被困洗头房每天接客十几次(图)</a><br/>      <a href="#">组图:老妻少夫演绎忘年恋69岁妻子成功除皱</a><br/>      <a href="#">陕西蓝田县电视台播放淫秽影像 达10分钟左右</a><br/>      <a href="#">女子自称被大学教授诱骗同居讨要分手费(图)</a><br/>      <a href="#">组图:男女私处成造型“性”趣礼品太出格</a><br/>      <a href="#">组图:四川泸州16岁女孩打造中国第一丑女</a><br/>      <a href="#">最高法:承诺不判赖昌星死刑没有超越法律程序</a><br/>      <a href="#">深圳发现睾丸被摘男童尸体续:疑为1月前失踪</a><br/>      <div align="right"><a href="#" target=_self>...more</a></div>    </span>     <span> <a href="#">养路费征稽员强制扣车致三轮车夫惨死车轮下</a><br/>      <a href="#">20多位学者谈中医问题 方舟子遭多名专家批驳</a><br/>      <a href="#">考研女生自称揭露监考老师作弊 成绩被判零分</a><br/>      <a href="#">全国政协委员建议一户一房制引起网民热议</a><br/>      <a href="#">河南周口市6名警察将人打昏后扔下楼摔死</a><br/>      <a href="#">组图:69岁老妻除皱成功 与少夫开始新生活</a><br/>      <a href="#">青海女孩被困洗头房每天接客十几次(图)</a><br/>      <a href="#">美上将:解放军不是美军对手 导弹打不垮台湾</a><br/>      <a href="#">新疆阜康铁路桥梁坍塌导致运煤列车脱轨</a><br/>      <a href="#">铁道部回应吴敬琏质疑:春运不涨价将长期坚持</a><br/>      <div align="right"><a href="#">...more</a></div>    </span>     </div>  </div></div><script type="text/javascript">  var Tags=document.getElementById('NewsTop_tit').getElementsByTagName('p');   var TagsCnt=document.getElementById('NewsTop_cnt').getElementsByTagName('span');   var len=Tags.length;   var flag=1;//修改默认值  for(i=1;i<len;i++){    Tags[i].value = i;    Tags[i].onmouseover=function(){                changeNav(this.value)    };     TagsCnt[i].className='undis';   }  Tags[flag].className='topC1';  TagsCnt[flag].className='dis';    function changeNav(v){     Tags[flag].className='topC0';    TagsCnt[flag].className='undis';    flag=v;     Tags[v].className='topC1';    TagsCnt[v].className='dis';  }</script></body></html>
Copy after login

The above code implements the most basic sliding door effect, which is also an example on the quoted network. Here is a brief introduction on how to implement this function:

1. Use four p elements in the header to make the navigation title, and use left floating to arrange the four p elements in a row, and set the next three Default CSS properties.

2. In terms of rotation content, several span elements are simply listed and displayed. You may be confused about the reason for the existence of the first span, which will be introduced below.

3. The above is the div css implementation of the code. Now let’s start with the street js to control the code to implement the sliding door:

document.getElementById('NewsTop_tit').getElementsByTagName('p') use To get the p tag collection of the title. document.getElementById('NewsTop_cnt').getElementsByTagName('span') is used to obtain the span element tag collection of the content.

Tags.length is used to get the number of p tags in the p tag set.

flag=1 is used to set a flag, which will be used in the following code.

The for loop statement is used to assign values ​​to each p tag and bind event processing functions to them. This time the for loop can extract the role of the first span element, because the first p tag It does not participate in sliding doors, so you must add an empty span tag corresponding to it, otherwise the for loop will cause errors when traversing span elements. The changeNav() event handler can change the background color of the p element of the first tab to gray and the font to black, hide the content span of the first tab, and set the p element and span of the corresponding values ​​​​to the current element. .

4. Tags[flag].className='topC1' and TagsCnt[flag].className='dis' after the for loop can be set. When the page is loaded, the default current p element and span element are both The first one.

The original address is: http://www.51texiao.cn/div_cssjiaocheng/2015/0501/511.html

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template