輕松實(shí)現(xiàn)jquery手風(fēng)琴效果
為大家講解的JQuery動(dòng)畫特效為手風(fēng)琴,廢話不多說(shuō),先看最終實(shí)現(xiàn)效果圖。
一、實(shí)現(xiàn)原理分析
對(duì)應(yīng)的立體圖:
二、 HTML代碼分析
<body> <div id="container"> <ul id="content"> <li class="first"> <h3>真</h3> <div><img src="images/0.jpg"/></div> </li> <li class="second"> <h3>的</h3> <div><img src="images/1.jpg"/></div> </li> <li class="third"> <h3>愛(ài)</h3> <div><img src="images/2.jpg"/></div> </li> <li class="forth"> <h3>你</h3> <div><img src="images/4.jpg"/></div> </li> </ul> </div> </body>
1. id為container的div就是上面分析中的紅色區(qū)域。
2. id為content的ul就是用來(lái)存放所有的li。
3. 每個(gè)li就是一個(gè)紅色區(qū)域與對(duì)應(yīng)圖片的組合。
三、CSS代碼分析
*{margin: 0; padding: 0;} img{ border:0; } #container { width:680px; height: 300px; margin: 100px auto; position: relative; border:3px solid red; overflow: hidden; } #container #content { list-style: none; } #container #content li{ width:590px; height:300px; position: absolute; } #container #content li.second{ left:590px; } #container #content li.third{ left:620px; } #container #content li.forth{ left:650px; } #container #content li h3{ float:left; width: 24px; height:294px; border:3px solid blue; background-color: yellow; cursor: pointer; } #container #content li div{ float: left; width: 560px; height:300px; }
1. *和img標(biāo)簽用來(lái)去除系統(tǒng)默認(rèn)的間隙等效果。
2. #container就是在上面分析的可視區(qū)域,所以它的尺寸是 680 * 300,并且它是所有子元素的容器,所以它是相對(duì)定位(position: relative)。
3. #container #content就是去除掉ul默認(rèn)的小圓點(diǎn)效果。
4. 所有的li采用絕對(duì)定位,并且它們的大小均為 590 * 300, 然后設(shè)置后面li的left值,并且設(shè)置li的h3(黃色區(qū)域)屬性漂浮。
當(dāng)上面所有的css樣式設(shè)置完畢以后,最終呈現(xiàn)的效果就是分析圖中的效果。
四、JQuery代碼分析
手風(fēng)琴的js交互代碼其實(shí)非常簡(jiǎn)單,就是實(shí)時(shí)的改變對(duì)應(yīng)li的絕對(duì)位置的left值就可以了,代碼如下:
$(function(){ $("#container #content li.first h3").mouseenter(function(){ $("#container #content li.second").stop().animate({"left":590}, 1000); $("#container #content li.third").stop().animate({"left":620}, 1000); $("#container #content li.forth").stop().animate({"left":650}, 1000); }); $("#container #content li.second h3").mouseenter(function(){ $("#container #content li.second").stop().animate({"left":30}, 1000); $("#container #content li.third").stop().animate({"left":620}, 1000); $("#container #content li.forth").stop().animate({"left":650}, 1000); }); $("#container #content li.third h3").mouseenter(function(){ $("#container #content li.second").stop().animate({"left":30}, 1000); $("#container #content li.third").stop().animate({"left":60}, 1000); $("#container #content li.forth").stop().animate({"left":650}, 1000); }); $("#container #content li.forth h3").mouseenter(function(){ $("#container #content li.second").stop().animate({"left":30}, 1000); $("#container #content li.third").stop().animate({"left":60}, 1000); $("#container #content li.forth").stop().animate({"left":90}, 1000); }); });
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。
相關(guān)文章
Javascript使用uploadify來(lái)實(shí)現(xiàn)多文件上傳
本篇文章主要介紹了Javascript使用uploadify來(lái)實(shí)現(xiàn)多文件上傳,具有一定的參考價(jià)值,有需要的可以了解一下。2016-11-11Nautil 中使用雙向數(shù)據(jù)綁定的實(shí)現(xiàn)
這篇文章主要介紹了Nautil 中使用雙向數(shù)據(jù)綁定的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10javascript中的window.location.search方法簡(jiǎn)介
window.location.search方法是截取當(dāng)前url中“?”后面的字符串,示例如下,感興趣的朋友可以參考下2013-09-09js window.open彈出新的網(wǎng)頁(yè)窗口
彈出新的網(wǎng)頁(yè)窗口的方法有很多,在本文為大家介紹下使用js的window.open方法來(lái)實(shí)現(xiàn),需要的朋友可以了解下2014-01-01ie 處理 gif動(dòng)畫 的onload 事件的一個(gè) bug
ie 處理 gif動(dòng)畫 的onload 事件的一個(gè) bug...2007-04-04JavaScript數(shù)據(jù)結(jié)構(gòu)之單鏈表和循環(huán)鏈表
這篇文章主要介紹了JavaScript數(shù)據(jù)結(jié)構(gòu)之單鏈表、循環(huán)鏈表,詳細(xì)的介紹了JavaScript如何實(shí)現(xiàn)單鏈表、循環(huán)鏈表,有興趣的可以了解一下2017-11-11JavaScript設(shè)計(jì)模式組合設(shè)計(jì)模式案例
這篇文章主要介紹了JavaScript設(shè)計(jì)模式組合設(shè)計(jì)模式案例,組合設(shè)計(jì)模式是用于將多個(gè)部分通過(guò)組合的方式行成一個(gè)整體,更多相關(guān)內(nèi)容需要的小伙伴可以參考一下2022-06-06