JS實(shí)現(xiàn)的另類手風(fēng)琴效果網(wǎng)頁(yè)內(nèi)容切換代碼
本文實(shí)例講述了JS實(shí)現(xiàn)的另類手風(fēng)琴效果網(wǎng)頁(yè)內(nèi)容切換代碼。分享給大家供大家參考。具體如下:
這是一款以海賊王為題材的另類手風(fēng)琴效果,用到三張背景圖片,請(qǐng)順著代碼自已下載吧,多看看類似特效的編寫(xiě)思路,對(duì)于提高你的Js編程水平有不少幫助的。
運(yùn)行效果截圖如下:
在線演示地址如下:
http://demo.jb51.net/js/2015/js-sfq-web-cha-style-codes/
具體代碼如下:
<!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:0px;padding:0px;overflow:hidden;background:#151515;} #box{width:710px;height:350px;padding:2px 0 2px 2px;margin:210px auto;background:#111;} #box ul{margin:0px;padding:0px;float:left;} #box li{width:75px;height:350px;float:left;display:inline;margin-right:2px;overflow:hidden;list-style-type:none;position:relative;} .pos1, .pos2, .pos3, .pos4, .pos5{width:75px;height:350px;float:left;text-decoration:none;} .pos1 span, .pos2 span, .pos3 span, .pos4 span, .pos5 span{width:75px;height:350px;float:left;top:0px;left:0px;filter:alpha(opacity=10);opacity:0.1;overflow:hidden;position:absolute; text-decoration:none;} .pos1 span.preview{background:url(images/bw.jpg) no-repeat;} .pos1 span.img_pre{left:75px;background:url(images/color.jpg) no-repeat;} .pos2 span.preview{background:url(images/bw.jpg) no-repeat -75px 0;} .pos2 span.img_pre{left:75px;background:url(images/color.jpg) no-repeat -75px 0;} .pos3 span.preview{background:url(images/bw.jpg) no-repeat -152px 0;} .pos3 span.img_pre{left:75px;filter:alpha(opacity=100);opacity:1;background:url(images/color.jpg) no-repeat -152px 0;} .pos4 span.preview{background:url(images/bw.jpg) no-repeat -228px 0;} .pos4 span.img_pre{left:75px;background:url(images/color.jpg) no-repeat -228px 0;} .pos5 span.preview{background:url(images/bw.jpg) no-repeat -303px 0;} .pos5 span.img_pre{left:75px;background:url(images/color.jpg) no-repeat -303px 0;} .inner {width:280px;height:310px;float:left;padding:20px;background:#fff;overflow:hidden;border-right:5px solid #f0f0f0; position:absolute;top:0px;left:75px;} .inner h2{width:280px;height:60px;float:left;color:#555555;font-family:"微軟雅黑";line-height:60px;font-size:18px;text-indent:10px;margin:0px;padding:0px;background:url(images/stripe_light.gif);} .inner h3{width:280px;height:40px;float:left;color:#fff;font-family:"微軟雅黑";line-height:40px;font-size:14px;text-indent:10px;margin:0px;padding:0px;background:url(images/stripe.gif);} .inner p{width:260px;height:200px;float:left;color:#000;font-family:"微軟雅黑";line-height:25px;font-size:12px;margin:0px;padding:0px 10px;} </style> <script type="text/javascript"> window.onload = function(){ var oBox = document.getElementById('box'); var aLi = oBox.getElementsByTagName('li'); var aA = oBox.getElementsByTagName('a'); var aPrev = getClass(oBox, 'preview'); var aImg = getClass(oBox, 'img_pre'); var i = 0; for(i=0;i<aA.length;i++){ aA[i].index = i; aA[i].onclick = function(){ for(i=0;i<aLi.length;i++){ if(aLi[this.index].style.width != '400px')startMove(aLi[i], {width:75}, 5); startMove(aPrev[i], {opacity:10}, 5); startMove(aImg[i], {opacity:0, left:75}, 5); } if(aLi[this.index].style.width != '400px'){ startMove(oBox, {width:710}, 5); startMove(aImg[this.index], {opacity:100, left:0}, 5); startMove(aLi[this.index], {width:400}, 5); }else{ startMove(aLi[this.index], {width:75}, 5); for(i=0;i<aLi.length;i++){ startMove(aPrev[i], {opacity:100}, 5); } startMove(oBox, {width:385}, 5); } }; } }; function getClass(oParent, sClass){ var aElem = oParent.getElementsByTagName('*'); var aClass = []; var i = 0; for(i=0;i<aElem.length;i++)if(aElem[i].className == sClass)aClass.push(aElem[i]); return aClass; } function startMove(obj, json, iT, fnEnd){ if(obj.timer)clearInterval(obj.timer); obj.timer = setInterval(function (){ doMove(obj, json, iT, fnEnd); }, 30); } function getStyle(obj, attr){ return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj, false)[attr]; } function doMove(obj, json, iT, fnEnd){ var iCur = 0; var attr = ''; var bStop = true; for(attr in json){ attr == 'opacity' ? iCur = parseInt(100*parseFloat(getStyle(obj, 'opacity'))) : iCur = parseInt(getStyle(obj, attr)); if(isNaN(iCur))iCur = 0; var iSpeed = (json[attr]-iCur) / iT; iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed); if(parseInt(json[attr])!=iCur)bStop = false; if(attr=='opacity'){ obj.style.filter = "alpha(opacity:"+(iCur+iSpeed)+")"; obj.style.opacity = (iCur + iSpeed) / 100; }else{ attr == 'zIndex' ? obj.style[attr] = iCur + iSpeed : obj.style[attr] = iCur + iSpeed +'px'; } } if(bStop){ clearInterval(obj.timer); obj.timer = null; if(fnEnd)fnEnd(); } } </script> </head> <body> <div id="box"> <li> <a href="javascript:;" class="pos1"> <span class="preview"></span> <span class="img_pre"></span> </a> <div class="inner"> <h2>烏索普</h2> <h3>草帽海賊團(tuán)【狙擊手】</h3> <p>懸賞:3000萬(wàn)(司法島事件)</p> </div> </li> <li> <a href="javascript:;" class="pos2"> <span class="preview"></span> <span class="img_pre"></span> </a> <div class="inner"> <h2>羅羅諾亞·索隆</h2> <h3>草帽海賊團(tuán)【劍士】</h3> <p>懸賞:6千萬(wàn)(阿拉巴斯坦事件)→1億2000萬(wàn)(司法島事件)</p> </div> </li> <li style="width:400px;"> <a href="javascript:;" class="pos3"> <span class="preview"></span> <span class="img_pre" style="left:0px;"></span> </a> <div class="inner"> <h2>蒙其·D·路飛</h2> <h3>草帽海賊團(tuán)【船長(zhǎng)】</h3> <p>惡魔果實(shí):橡膠果實(shí)<br />懸賞:3千萬(wàn)(可可亞西村事件)→1億(阿拉巴斯坦事件)→3億(司法島事件)→4億(頂上戰(zhàn)爭(zhēng)后)</p> </div> </li> <li> <a href="javascript:;" class="pos4"> <span class="preview"></span> <span class="img_pre"></span> </a> <div class="inner"> <h2>娜美</h2> <h3>草帽海賊團(tuán)【航海士】</h3> <p>懸賞:1600萬(wàn)(司法島事件)</p> </div> </li> <li> <a href="javascript:;" class="pos5"> <span class="preview"></span> <span class="img_pre"></span> </a> <div class="inner"> <h2>香吉士</h2> <h3>草帽海賊團(tuán)【廚師】</h3> <p>懸賞:7700萬(wàn)(司法島事件)</p> </div> </li> </div> </body> </html>
希望本文所述對(duì)大家的JavaScript程序設(shè)計(jì)有所幫助。
- js以及jquery實(shí)現(xiàn)手風(fēng)琴效果
- 原生JS實(shí)現(xiàn)垂直手風(fēng)琴效果
- Html5 js實(shí)現(xiàn)手風(fēng)琴效果
- 炫酷的js手風(fēng)琴效果
- 純js實(shí)現(xiàn)手風(fēng)琴效果代碼
- 純js實(shí)現(xiàn)手風(fēng)琴效果
- JS實(shí)現(xiàn)仿QQ面板的手風(fēng)琴效果折疊菜單代碼
- 原生js做的手風(fēng)琴效果的導(dǎo)航菜單
- js實(shí)現(xiàn)可折疊展開(kāi)的手風(fēng)琴菜單效果
- js實(shí)現(xiàn)簡(jiǎn)單的手風(fēng)琴效果
相關(guān)文章
javascript手風(fēng)琴下拉菜單實(shí)現(xiàn)代碼
手風(fēng)琴效果的下拉菜單大家都有見(jiàn)到過(guò)吧,實(shí)現(xiàn)的方法也有很多,這篇文章就為大家分享了javascript手風(fēng)琴下拉菜單實(shí)現(xiàn)代碼,純手寫(xiě)的,感興趣的朋友不要錯(cuò)過(guò)。2015-11-11一文熟練掌握J(rèn)avaScript的switch用法
在JavaScript中switch語(yǔ)句是一種用于多條件分支的控制語(yǔ)句,下面這篇文章主要給大家介紹了關(guān)于如果通過(guò)一文熟練掌握J(rèn)avaScript的switch用法的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-01-01JS尾遞歸的實(shí)現(xiàn)方法及代碼優(yōu)化技巧
這篇文章主要介紹了JS尾遞歸的實(shí)現(xiàn)方法及代碼優(yōu)化技巧,結(jié)合實(shí)例形式分析了尾遞歸的原理、JS實(shí)現(xiàn)方法及優(yōu)化技巧,需要的朋友可以參考下2019-01-01jQuery AJAX回調(diào)函數(shù)this指向問(wèn)題
了解JavaScript的人都知道JavaScript的this不總是指向當(dāng)前對(duì)象,函數(shù)或類中的this指向與調(diào)用這個(gè)函數(shù)的對(duì)象以及上下文環(huán)境是息息相關(guān)的。2010-02-02原生javascript中this幾種常見(jiàn)用法總結(jié)
這篇文章主要介紹了原生javascript中this幾種常見(jiàn)用法,結(jié)合實(shí)例形式總結(jié)分析了JavaScript中this的功能、常見(jiàn)用法及操作注意事項(xiàng),需要的朋友可以參考下2020-02-02JavaScript實(shí)現(xiàn)動(dòng)態(tài)表格效果
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)動(dòng)態(tài)表格效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06Bootstrap輸入框組件簡(jiǎn)單實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了Bootstrap輸入框組件的簡(jiǎn)單實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03