- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) >
- JavaScript中圖片庫的示例分析
這篇文章將為大家詳細講解有關(guān)JavaScript中圖片庫的示例分析,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
一、一個(gè)javascript 圖片庫實(shí)例,下面是效果圖
點(diǎn)擊頂部導航,會(huì )在本頁(yè)面進(jìn)行刷新圖片,然后,在底部會(huì )顯示文本的變化
二、下面是代碼
1、gallery.html代碼
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript" src="js/showPic.js"></script> <link rel="stylesheet" type="text/css" href="css/layout.css" rel="external nofollow" /> </head> <body> <h2>Snapshots</h2> <ul> <li> <a href="img/a.jpg" rel="external nofollow" title="Hongse Fengye" onclick="showPic(this);return false;">紅色楓葉</a> </li> <li> <a href="img/b.jpg" rel="external nofollow" title="Huangse Fengye" onclick="showPic(this); return false;">黃色楓葉</a> </li> <li> <a href="img/c.jpg" rel="external nofollow" title="Hongse Shu" onclick="showPic(this); return false;">紅色樹(shù)</a> </li> <li> <a href="img/d.jpg" rel="external nofollow" title="Lanse Fengye" onclick="showPic(this);return false;">藍色楓葉</a> </li> </ul> <img src="img/3302-106.jpg" id="placeholder" alt="My Gallery"/> <p id="description">Choose an image</p> </body> </html>
2、showPics.js代碼
function showPic(whichpic){ var sorce=whichpic.getAttribute("href"); var placeholder=document.getElementById("placeholder"); placeholder.setAttribute("src",sorce); var text=whichpic.getAttribute("title"); var description=document.getElementById("description"); description.firstChild.nodeValue=text; }
3、layout.css代碼
img{ width: 600px; } body{ font-family: helvetica,arial,serif; color: #333; background-color: #ccc; margin: 1em 10%; } h2{ color:#333; background-color: transparent; } a{ color: #c60; background-color: transparent; font-weight: bold; text-decoration: none; } ul{ padding: 0; } li{ float: left; padding: 1em; list-style: none; } img{ display: block; clear: both; }
三、幾個(gè)新的DOM屬性
1、childNodes
獲得 body 元素的子節點(diǎn)集合:
document.body.childNodes;
2、nodeType
獲得 body 元素的節點(diǎn)類(lèi)型:
document.body.nodeType;
3、nodeValue
nodeValue 屬性設置或返回指定節點(diǎn)的節點(diǎn)值。
4、firstChild、lastChild
firstChild 屬性返回指定節點(diǎn)的首個(gè)子節點(diǎn),以 Node 對象。
lastChild 屬性返回指定節點(diǎn)的最后一個(gè)子節點(diǎn),以 Node 對象。
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自互聯(lián)網(wǎng)轉載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權請聯(lián)系QQ:712375056 進(jìn)行舉報,并提供相關(guān)證據,一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容。
Copyright ? 2009-2021 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 珠海市特網(wǎng)科技有限公司 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站