搜狐的滑动门效果代码

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html  xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta  http-equiv ="Content-Type"  content ="text/html; charset=utf-8"   />
< title > 无标题文档 </ title >
< style  type ="text/css" >
<!--
body
{  margin : 0 ;  padding : 0 ;  border : 0 ;  font : 12px "宋体" }
div,ul,li
{  margin : 0 ;  padding : 0 ;  border : 0 }
li
{  list-style : none }
.tab
{  float : left ; background : url(http://bbs.blueidea.com/attachment.php?aid=77070&noupdate=yes)  120px 0 repeat-y ; height : 182px ;  overflow : auto  }
.tab li
{  width : 108px ;  height : 30px ;  line-height : 30px ; margin-bottom : 9px ;  padding-left : 13px }
.tabNomorl
{  background : url(http://bbs.blueidea.com/attachment.php?aid=77070&noupdate=yes) -1px 0 no-repeat ;  cursor : pointer }
.tabHover
{  background : url(http://bbs.blueidea.com/attachment.php?aid=77070&noupdate=yes) -1px -29px no-repeat }
.box
{  float : left ;  width : 410px ;  height : 160px ;  border : 1px solid #FAB208 ;  border-left : none ;  padding : 10px }
-->
</ style >
< script  type ="text/javascript" >
// <![CDATA[
function  getNextElement(obj) {
    
var  result  =  obj.nextSibling;
    
while  ( ! result.tagName) {
        result 
=  result.nextSibling;
    }
    
return  result;
}
function  tab(obj,index) {
    
var  index  =  index  -   1 ;
    
var  tabobj  =  document.getElementById(obj);
    
var  tablist  =  tabobj.getElementsByTagName( " LI " );
    
    
var  boxobj  =  getNextElement(tabobj);
    
var  boxlist  =  boxobj.getElementsByTagName( " DIV " );
    
    
for  ( var  i = 0 ; i < tablist.length; i ++ ) {
        
var  cname,ds;
        
if   (i  ==  index) {
            cname 
=    " tabHover " ;
            ds 
=   " block " ;
        } 
else  {
            cname 
=    " tabNomorl " ;
            ds 
=   " none " ;    
        }
        boxlist[i].style.display 
=  ds;
        tablist[i].className 
=  cname;
        tablist[i].i 
=  i;
        tablist[i].onclick 
=   function () {
            tabclick(
this .i);
        }
        
        
function  tabclick(j) {
            tablist[index].className 
=   " tabNomorl " ;
            boxlist[index].style.display 
=   " none " ;    
            tablist[j].className 
=   " tabHover " ;
            boxlist[j].style.display 
=   " block " ;
            index 
=  j;
        }
    }
}
window.onload 
=   function () {
    
new  tab( " tab1 " , 2 );
    
new  tab( " tab2 " , 3 );
}
// ]]>
</ script >
</ head >
< body >
< div  style ="margin:30px; height:auto;overflow:auto" >
  
< ul  id ="tab1"  class ="tab" >
    
< li > 匹配度1 </ li >
    
< li > 匹配度2 </ li >
    
< li > 匹配度3 </ li >
    
< li > 匹配度4 </ li >
  
</ ul >
  
< div  class ="box" >
    
< div > 匹配度1 </ div >
    
< div > 匹配度2 </ div >
    
< div > 匹配度3 </ div >
    
< div > 匹配度4 </ div >
  
</ div >
</ div >
< div  style ="padding:60px; height:900px" >
  
< ul  id ="tab2"  class ="tab" >
    
< li > 匹配度1 </ li >
    
< li > 匹配度2 </ li >
    
< li > 匹配度3 </ li >
    
< li > 匹配度4 </ li >
  
</ ul >
  
< div  class ="box" >
    
< div > 匹配度1 </ div >
    
< div > 匹配度2 </ div >
    
< div > 匹配度3 </ div >
    
< div > 匹配度4 </ div >
  
</ div >
</ div >
</ body >
</ html >

转载于:https://www.cnblogs.com/chen79/archive/2008/01/21/1047219.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用 JavaScript 实现简洁的左侧滑动门菜单(选项卡)效果代码: HTML 代码: ``` <div class="menu"> <div class="tab active" data-tab="tab1">Tab 1</div> <div class="tab" data-tab="tab2">Tab 2</div> <div class="tab" data-tab="tab3">Tab 3</div> <div class="slider"></div> </div> <div class="content"> <div class="tab-content active" data-tab="tab1">Content for Tab 1</div> <div class="tab-content" data-tab="tab2">Content for Tab 2</div> <div class="tab-content" data-tab="tab3">Content for Tab 3</div> </div> ``` CSS 代码: ``` .menu { display: flex; flex-direction: column; position: relative; width: 200px; height: 300px; background-color: #f0f0f0; } .tab { display: flex; align-items: center; justify-content: center; width: 100%; height: 50px; cursor: pointer; } .tab.active { background-color: #ccc; } .slider { position: absolute; top: 0; left: 0; width: 5px; height: 50px; background-color: #000; transition: transform 0.3s ease-in-out; } .content { flex: 1; padding: 10px; } .tab-content { display: none; } .tab-content.active { display: block; } ``` JavaScript 代码: ``` // 获取菜单和标签页元素 const tabs = document.querySelectorAll('.tab'); const tabContents = document.querySelectorAll('.tab-content'); const slider = document.querySelector('.slider'); // 给菜单项添加事件监听器 tabs.forEach(tab => { tab.addEventListener('click', () => { // 移除所有菜单项的 active 类 tabs.forEach(item => { item.classList.remove('active'); }); // 给当前点击的菜单项添加 active 类 tab.classList.add('active'); // 获取当前菜单项的索引值 const index = Array.from(tabs).indexOf(tab); // 移动滑动门到当前菜单项的位置 slider.style.transform = `translateY(${index * 50}px)`; // 隐藏所有标签页 tabContents.forEach(content => { content.classList.remove('active'); }); // 显示对应的标签页 tabContents[index].classList.add('active'); }); }); ``` 以上代码实现了一个左侧滑动门菜单(选项卡)效果,可以根据实际需求进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值