2012-04-10 51 views
0

當某人懸停在我的頁面上的圖像上時,如何創建此簡單jQuery效果?將鼠標懸停在圖像上時創建簡單的jQuery滑動效果

JSFiddle示例can be found here

enter image description here

我希望當有人進入的圖像或箱的任何部分,文本區域應擴大透露更多的細節。

在鼠標離開時,文本區域應該縮小並且只允許圖像可見。

這裏是我的嘗試:

$("#free-roster .roster-container .champion").mouseenter(function() { 
    $(this).find(".info").animate({ width: "116px" }, 400); 
}); 

$("#free-roster .roster-container .champion").mouseleave(function() { 
    $(this).find(".info").animate({ width: "0px" }, 400); 
}); 
+1

這是什麼'$(「#。champion」)'。你在抓班還是ID? – elclanrs 2012-04-10 02:16:57

+0

我不是爲什麼它複製這種方式,修復它。有一個實例可以看到我在說什麼,謝謝! – 2012-04-10 02:18:41

回答

0

這個jQuery工作對我來說:

$("#free-roster .roster-container .champion").mouseenter(function() { 
    $(this).find(".info").animate({ width: "116px" }, 400); 
}); 

$("#free-roster .roster-container .champion").mouseleave(function() { 
    $(this).find(".info").animate({ width: "0px" }, 400); 
}); 

$("#free-roster .roster-container .champion").mouseleave(); 

在你的CSS地址:

color: white; 

到:

#free-roster .roster-container .champion .info 

http://jsfiddle.net/9EFsE/1/

+0

這樣做的問題是'.info'被附加到內聯css樣式:'display:block',導致它出現在圖像下面。我希望它能夠拉伸灰色容器框以適應文字。任何其他想法? – 2012-04-10 02:58:28

+0

在IE9和Firefox 11中,文本顯示在圖片旁邊,如上面截圖所示。我沒有更老的瀏覽器可以看,但我在過去使用display:inline-block有一些運氣 – 2012-04-10 03:01:44