国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

js實現(xiàn)的切換面板實例代碼

2024-05-06 15:46:38
字體:
供稿:網(wǎng)友
切換面板具備功能:鼠標劃過不同的題目會有不同的圖片和解說,可以連接到不同的網(wǎng)站,實例代碼如下,感興趣的朋友可以參考下哈

最近小菜鳥看了妙味課堂的js視頻,學習了一點知識,在這里總結(jié)一下,代碼寫的有點臃腫,剛開始學,不知道咋著優(yōu)化,看到的高手可以指點一下,呵呵,再此謝過,
效果大概是在這樣的:

js實現(xiàn)的切換面板實例代碼


鼠標劃過不同的題目會有不同的圖片和解說,可以連接到不同的網(wǎng)站,
分享一下我的代碼:

復(fù)制代碼 代碼如下:


<!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">
<!--
*{ margin:0; padding:0;}
#container{ height:auto; width:553px; border:1px solid #CCC; position:relative; margin:100px auto;}
#content{ height:266px; width:400px; position:relative; background:#F00; float:left;}
#content p{ color:#FFF; padding:10px; height:30px; width:380px; position:absolute; left:0; bottom:0;}
#content p:nth-child(1){ z-index:2;}
#content p:nth-child(even){ background:#000; opacity:0.5;}
#menu{ height:160px; width:153px; float:right;}
#menu ul{ height:100%; width:100%;}
#menu ul li{ text-align:center;background:#F6F6F6; position:relative;list-style:none; display:block; height:65px; width:153px; border-bottom:1px solid #CCC;}
#menu ul li:last-child{ height:68px; border:none;}
#menu ul li a{ text-decoration:none;color:#000; text-align:center; line-height:65px; font-size:16px;}
#menu ul li a:hover{ color:#F00;}
span{ z-index:2;
height:0;
width: 0;
border-color: transparent #f6f6f6 transparent transparent;
border-width:33px;
border-style: solid;
}
.one{
position: absolute;
top: 0;
left: -66px;
}
.two{
position: absolute;
left:-66px;
top:0;
}
.three{
position: absolute;
left: -66px;
top:0;
}
.four{
position: absolute;
border-width:34px;
left: -68px;
top:0;
}
img{ border:none;}
-->
</style>
<script type="text/javascript">
window.onload=function(){
var obj=document.getElementById('menu').getElementsByTagName('li');/*獲取id為menu的容器中的所有l(wèi)i元素*/
var con=document.getElementById('content').getElementsByTagName('img')[0];/*獲取content里面出現(xiàn)的第一個img對象*/
var hreff=document.getElementById('content').getElementsByTagName('a')[0];
var hrefLink=new Array('http://www.baidu.com','http://weibo.com/2622932383/profile?topnav=1&wvr=5','http://www.taobao.com','http://google.com.hk')/*存所有連接的數(shù)組*/
var words=new Array('我的小破車','雜草叢生,是希望','小伙伴在張望','鋼索通向遠方');/*每張圖片的解說詞存放在數(shù)組里*/
var pContent=document.getElementById('content').getElementsByTagName('p')[0];/*獲取存放解說詞的p元素*/
var i=0;
for(i=0;i<obj.length;i++)
{
obj[i].index=i;
obj[i].onmouseover=function(){
con.src='images/photo'+(this.index+1)+'.jpg';
pContent.innerHTML=words[this.index];
hreff.href=hrefLink[this.index];
}
}
}
</script>
</head>
<body>
<div>
<div>
<p>我的小破車</p>
<p></p>
<a ><img src="images/photo1.jpg"/></a></div>
<div>
<ul>
<li><a href="#">語文詳解</a><span></span></li>
<li><a href="#">數(shù)學詳解</a><span></span></li>
<li><a href="#">php進階</a><span></span></li>
<li><a href="#">c++惡補</a><span></span></li>
</ul>
</div>
<div></div>
</div>
</body>
</html>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 池州市| 清水县| 青冈县| 布尔津县| 综艺| 无棣县| 界首市| 鄱阳县| 镇平县| 无棣县| 英吉沙县| 津南区| 天柱县| 潍坊市| 西乌珠穆沁旗| 临湘市| 台北市| 花莲市| 珲春市| 五河县| 新河县| 安庆市| 尚义县| 苏尼特左旗| 阿鲁科尔沁旗| 平和县| 星子县| 寿阳县| 娱乐| 屏东市| 淮阳县| 襄城县| 辽阳市| 紫云| 公主岭市| 凤山县| 通江县| 云南省| 定兴县| 昭平县| 靖江市|