課程
/前端開(kāi)發(fā)
/HTML/CSS
/DOM探索之基礎(chǔ)詳解篇
sublime里js代碼高亮用什么插件啊
2016-03-13
源自:DOM探索之基礎(chǔ)詳解篇 1-3
正在回答
以上是案例完整的代碼,加了css3動(dòng)畫(huà),鼠標(biāo)離開(kāi)時(shí)可以恢復(fù)到原始位置(注釋部分)。
<!DOCTYPE?html> <html> <head> <meta?charset="UTF-8"> <title>滑動(dòng)門(mén)特效</title> <link?rel="stylesheet"?href="css/style.css"> </head> <body> <div?id="container"> <img?src="images/door1.png"?alt="door1"?title="door1"> <img?src="images/door2.png"?alt="door2"?title="door2"> <img?src="images/door3.png"?alt="door3"?title="door3"> <img?src="images/door4.png"?alt="door4"?title="door4"> </div> </body> <script?src="js/script.js"></script> </html>
*{ margin:0; padding:0; } #container{ position:relative; height:?477px; margin:20px?auto; border-bottom:1px?solid?#d9d9d9; border-right:1px?solid?#d9d9d9; overflow:?hidden; } #container?img{ position:?absolute; left:0; display:block; border-right:?1px?solid?#d9d9d9; transition:?all?0.5s; } #container?img:nth-child(1){ border-left:?1px?solid?#d9d9d9; }
window.onload?=?function(){ //獲取盒子對(duì)象 var?box?=?document.getElementById('container'); //獲取圖片對(duì)象 var?imgs?=?box.getElementsByTagName('img'); var?imgWidth?=?imgs[0].offsetWidth;?//單張圖片的寬度 var?exposeWidth?=?160; //隱藏門(mén)露出寬度 var?boxWidth?=?imgWidth+exposeWidth*(imgs.length-1); //圖片盒子寬度 box.style.width?=?boxWidth+'px'; //設(shè)置每道門(mén)的初始位置 function?setImgsPos(){ for(var?i=1;i<imgs.length;i++){ imgs[i].style.left?=?imgWidth?+?exposeWidth*(i-1)+'px'; } } setImgsPos(); //?計(jì)算每張圖片移動(dòng)的距離 var?translate?=?imgWidth?-?exposeWidth; //為每道門(mén)綁定事件 for(var?i=0;i<imgs.length;i++){ (function(i){ imgs[i].onmouseover?=?function()?{ setImgsPos(); //打開(kāi)門(mén) for?(var?j?=?1;j<=i;j++)?{ imgs[j].style.left?=?parseInt(imgs[j].style.left,10)?-?translate?+?'px'; //10代表十進(jìn)制 } }; })(i); } //鼠標(biāo)移出后復(fù)位 //?for(var?i=0;i<imgs.length;i++){ //? imgs[i].onmouseleave?=?function(){ //? setImgsPos(); //? } //?} };
舉報(bào)
要知道前端大牛都是從精通DOM開(kāi)始的,全面講解DOM的基礎(chǔ)知識(shí)
4 回答dom是什么?。扛鷍s有關(guān)系嗎?
2 回答請(qǐng)問(wèn)老師的sublime用的什么字體?
6 回答這行代碼中的10表示什么意思啊
3 回答用什么軟件?
3 回答我把js放到頭文件里怎么就不運(yùn)行了呢?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-03-13
以上是案例完整的代碼,加了css3動(dòng)畫(huà),鼠標(biāo)離開(kāi)時(shí)可以恢復(fù)到原始位置(注釋部分)。
2016-03-13
2016-03-13
2016-03-13