2014-10-01 56 views
1

我試圖在以下網站上創建效果:http://www.cssplay.co.uk/menu/css3-animation.html#x。我的代碼目前只使用兩個圖像,但我將使用大約10到15作爲最終動畫。我試圖實現懸停查看動畫,第二個圖像,而不是點擊效果。下面的代碼:懸停以查看與CSS鏈接的動畫

 
 
    .footer nav ul.homeandlist li { 
 
     display: block; 
 
     width: 40%; 
 
     height: 150px; 
 
     float: left; 
 
     margin: 1% 3%; 
 
     background-color: rgba(255, 165, 0, 0.11); 
 
    } 
 
    .footer nav ul.homeandlist a { 
 
     margin: 0; 
 
     padding: auto; 
 
     width: 100%; 
 
     height: 90px; 
 
     text-indent: -9000px; 
 
     line-height: 2em; 
 
     font-size: 16px; 
 
     display: block; 
 
    } 
 
    .footer nav ul.homeandlist .GetOnList { 
 
     position: relative; 
 
     width: 40%; 
 
     height: 150px; 
 
    } 
 
    .footer nav ul.homeandlist .GetOnList a { 
 
     display: block; 
 
     -webkit-transition: z-index 0.1s linear; 
 
     transtion: z-index 0.1s linear; 
 
    } 
 
    .footer nav ul.homeandlist .GetOnList a#a1 { 
 
     background: url('images/image1.png'); 
 
    } 
 
    .footer nav ul.homeandlist .GetOnList a#a2 { 
 
     background: url('images/image2.png'); 
 
    } 
 
    .footer nav ul.homeandlist .hover a:hover { 
 
     z-index: 20; 
 
    } 
 
    .footer nav ul.homeandlist .hover a:hover + a { 
 
     z-index: 30; 
 
    } 
 
    .footer nav ul.homeandlist .hover a#a1 { 
 
     z-index: 20; 
 
    } 
 
    .footer nav ul.homeandlist .hover a#a2 { 
 
     z-index: 10; 
 
    }
<div class="footer"> 
 

 
    <nav> 
 

 
    <p class="footertext">Text will go here</p> 
 
    <div class="clear"></div> 
 
    <ul class="homeandlist"> 
 

 
     <li class="GetOnList hover"> 
 
     <a id="a1" href="GetOnList.html">Get On List</a> 
 
     <a id="a2" href="GetOnList.html">Get On List</a> 
 
     </li> 
 

 
     <li class="HomeLink"><a href="index.html" title="HomeLink">HomeLink</a> 
 
     </li> 
 

 
    </ul> 
 

 
    
 
    </nav> 
 

 

 

 
</div>

到目前爲止,只有圖像1顯示了,但沒有任何反應懸停。對我來說,看起來我使用的是與網站上使用的代碼相同的代碼。有任何想法嗎?
我編輯了代碼,刪除可能無關緊要的部分。如果需要更多代碼,請告訴我,我可以包含您需要的內容,但這應該涵蓋它。

+0

你應該把僅有的事項代碼。 – 2014-10-01 02:56:58

回答

0

這裏有一個新的例子:http://jsbin.com/wixume/5/edit

代碼使用選擇器來

標記:

<div class="footer"> 
    <nav> 
    <ul class="homeandlist"> 
     <li id="addedId"><a id="a1">Get On List</a></li> 
     <li id="anotherAddedId"><a id="a2">Get On List</a></li> 
     <li id="lastOne"><a id="a3">Get On List</a></li> 
    </ul> 
    </nav> 
</div> 

CSS:

.footer nav ul.homeandlist li { 
     display: block; 
} 
.footer nav ul.homeandlist a { 
     width: 100%; 
     height: 90px; 
     display: block; 
} 
a{ 
position:absolute; 
} 
.footer nav ul.homeandlist li { 
    position: absolute; 
    width: 40%; 
    height: 150px; 
} 
.footer nav ul.homeandlist li { 
    display: block; 
    -webkit-transition: z-index 0.9s linear; 
    transtion: z-index 0.9s linear; 
} 
#a1 { 
    background-color: red; 
} 
#a2 { 
    background-color: yellow; 
} 
#a3 { 
    background-color: blue; 
} 
#addedId:hover { 
    /* Move the first one to the bottom when hover*/ 
    z-index: 9; 
} 
li:hover + li { 
    /* 
    Move the second li to the top 
    If move mouse, the element below it gets selected and moved to the top. 
    ...and so on for each one below that... 
    Once are hovering on the bottom one and we move, 
    nothing for a moment has a hover state so we can see the top li. 
    And then it starts all back over. 
    */ 
    z-index: 30; 
} 
#addedId { 
    z-index: 20; 
} 
#anotherAddedId { 
    z-index: 19; 
} 
#lastOne:{ 
    z-index:10; 
} 
+0

這似乎工作,但它與我引用的網站有點不同。一個問題是顏色看起來變化太快,當我將z-index轉換屬性上的時間更改爲更高的數字時,並不是所有的背景顏色都顯示出來。只是紅色和黃色似乎交替。你知道爲什麼我列出的代碼不起作用嗎?另外,.viewwindow .img:hover + .img {z-index:30}部分的具體做法是.img:hover + .img部分。加號是做什麼的? – 2014-10-04 02:35:01

+0

再次,你在做什麼似乎工作。但我認爲這不會解決問題。李的需要是分開的,看起來你所做的就是把3個li放到一個地方。在我的情況下,每個li都是一個鏈接到一個單獨的頁面,所以點擊它將導航到該網站的該部分。同時,每個李在盤旋時都會有動畫。我還沒有完全研究過你做過的事情,但乍看之下,它看起來並不像導航欄那樣工作。但是我認爲你在選擇器中加入了+。 – 2014-10-04 04:09:44

+0

是的,如果你選擇正確的話,它會適用於你的場景。 – 2014-10-04 05:33:11