任何人有任何想法,如果你可以在jQuery中做到這一點?點擊一張標誌展開其餘部分?示例圖片:展開標誌從一半
Q
展開標誌從一半
0
A
回答
0
不知道這是不是你想要的東西。
檢查這裏的演示:http://jsfiddle.net/SdanM/4/
HTML:
<div id="container">
<div id="img">Hidden Element</div>
<div id="btn">Hover to expand</div>
<div>
CSS:隱藏hidden element
第一
#container {
position: relative;
}
#img {
background-color: yellow;
position: absolute;
width: 100px;
height: 50px;
top: 50px;
left: 50px;
display: none;
}
#btn {
background-color: red;
position: absolute;
width: 50px;
height: 50px;
top: 50px;
left: 50px;
}
jQuery的:移動塊
$("#container").mouseenter(function() {
$("#img").animate({
left: "-=50",
width: "show",
}, 1000);
$("#btn").animate({
left: "+=50",
}, 1000);
});
$("#container").mouseleave(function() {
$("#img").animate({
left: "+=50",
width: "hide",
}, 1000);
$("#btn").animate({
left: "-=50",
}, 1000);
});
2
爲什麼使用jQuery如果這可以使用CSS來實現?
HTML:
<div id='icon-wrapper'>
<img id='icon' alt='icon' src='http://i.stack.imgur.com/sKhJf.jpg?s=60&g=1'/>
<p>Text here</p>
</div>
CSS:
#icon-wrapper{
margin:0 auto;
height:110px;
width:110px;
overflow:hidden;
/* CSS Transitions */
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-ms-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
}
#icon-wrapper:after{
content:"";
display:block;
width:100%;
clear:both;
}
#icon-wrapper:hover{
width:300px;
}
#icon-wrapper:hover #icon{
margin-left:200px;
}
#icon{
-webkit-border-radius: 100%;
-moz-border-radius: 100%;
border-radius: 100%;
/* Position Absolute to put the icon on the top */
position:absolute;
z-index:10;
/* CSS Transitions */
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-ms-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
}
#icon-wrapper p{
color:black;
font-size:35px;
font-family:arial, helvetica;
/* Fixed width and float left is needed */
width:200px;
float:left;
}
它的長,但不使用jQuery是一個加點。 請注意,我們需要使用固定寬度作爲元素,特別是段落。
UPDATE: 對於透明圖標,我們需要先使用opacity:0;來隱藏文本。然後添加CSS轉換,以便我們對懸停有平滑的效果。最後,用不透明度顯示懸停的文本:1 ;.但是這個技巧有一個缺陷,有時文本沒有「隱藏」得很快,所以它仍然會在圖標中顯示一段時間。最好的解決方案是爲圖標添加背景顏色,使用與容器背景相同的顏色。
更新CSS(透明文本):
#icon-wrapper:hover p{
opacity:1;
}
#icon-wrapper p{
/* ... */
opacity:0;
-webkit-transition: all 2s ease-in;
-moz-transition: all 2s ease-in;
-ms-transition: all 2s ease-in;
-o-transition: all 2s ease-in;
transition: all 2s ease-in;
}
更新CSS(使用在該圖標的背景顏色):
#icon{
/* ... */
background:white;
}
這裏是一個jsFiddle
這裏是更新的fiddle透明的圖標。
這裏是一個更新的fiddle背景顏色添加到圖標。
相關問題
- 1. QTreeWidget展開標誌
- 2. 帶有SVG標誌的動畫半圓
- 3. Hub Tiles動畫「半展開」中斷
- 4. 標誌展示IE問題
- 5. 展開一個元組半成品重複成對
- 6. 如果孩子存在,如何僅顯示TreeView展開標誌[+]
- 7. 在Makefile中從C++標誌中刪除一個標誌?
- 8. hlsl中的一半下標
- 9. 升壓program_options開/關標誌
- 10. 打開https標誌的cookie
- 11. UIAlertview標題隱藏一半 - 目標c
- 12. 展開從IO(a)
- 13. 正確使用〜參數擴展標誌?
- 14. 從半開放套接字讀取
- 15. Html在鼠標上展開
- 16. 展開和摺疊圖標
- 17. Bootstrap3 select change展開圖標
- 18. SlidingDrawer開始半打開
- 19. Chrome擴展程序記住從哪個標籤打開標籤
- 20. 打開從文本輸入一個新的標籤,從Chrome擴展
- 21. 通用擴展方法,如果枚舉包含一個標誌
- 22. C#擴展方法如果枚舉有一個標誌設置
- 23. NW:擴展龜半徑
- 24. 從字符串的第一半開始的子字符串
- 25. UIScrollView開始一半的內容
- 26. 顯示活動一半,並在android棉花糖拉起時展開
- 27. Android DrawerLayout鎖半開
- 28. 從圖像創建半透明光標
- 29. 從taskscheduleR擴展日誌記錄
- 30. 從uint16_t閱讀標誌
朋友,用我的標誌,它是透明的。我修改了一些東西,但它沒有工作...打印:http://clanload.com.br/images/3UrkL.png – user3413650
請看我的更新。 –