我有一些div塊。我需要擴大它自己的規模。像在MacOS Dock面板中一樣,當圖標被徘徊時。我可以這樣做嗎?JQuery/JavaScript塊縮放
1
A
回答
5
是的,你可以:
HTML:
<div class="scaleMe"> </div>
的jQuery:
$(function(){ /* makes sure your dom is ready */
$('div.scaleMe').hover(function(){
$(this).stop(false, true).animate({width:'50px', height:'50px'}, 1000) /* makes the div big on hover, and .stop() makes sure the annimation is not looping*/
},function(){
$(this).stop(false, true).animate({width:'20px', height:'20px'}, 600) /* goes back to normal state */
})
})
在這裏你可以找到一個OSX像碼頭使用jQuery做了一個很好的例子: http://www.ndesign-studio.com/blog/css-dock-menu
+0
這個菜單是真棒! – 2012-08-22 01:24:04
1
也許是這樣的?
$("#myDiv").hover(
function(){
$(this).css({height : scaled_height, width : scaled_width});
},
function(){
$(this).css({height : original_height, width : original_width});
}
);
0
我從http://jsbin.com/ecuzof/1/edit/得到了這個解決方案。感謝作者去了!我發現鏈接從http://forum.jquery.com/topic/i-want-to-resize-or-scale-the-div-on-hover。
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Zoom DIV on Hover</title>
<link href="http://code.jquery.com/ui/1.8.21/themes/base/jquery-ui.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://code.jquery.com/ui/1.8.21/jquery-ui.min.js"></script>
<style>
body{
font-size:162.5%;
}
</style>
<style>
.sectionToZoomOnHover {
display: table-cell;
text-align: center;
vertical-align: middle;
width: 200px;
height: 50px;
margin: 1em;
padding: 1.2em;
border: 1px solid gray;
background: yellow;
}
</style>
</head>
<body>
<div class="sectionToZoomOnHover">
Hover me. I'll grow
</div>
<script>
$(".sectionToZoomOnHover").hover(
function() {
$(this).stop().animate(
{
width: 360,
height: 100,
backgroundColor: "lightBlue",
fontSize: "3em"
}
);
}, function() {
$(this).stop().animate(
{
width: 200,
height: 50,
backgroundColor: "yellow",
fontSize: "1em"
}
);
}
);
</script>
</body>
</html>
不幸的是,我還沒有想出如何放大,使該DIV的中心點保持原樣,這是我真的想,太影響。
相關問題
- 1. Surface ScatterViewItem拖放塊縮放
- 2. 縮放地塊matplotlib
- 3. ggplot2 - 多個地塊縮放
- 4. 刪除`UIImagePickerController`縮放滑塊
- 5. 使用滑塊縮放
- 6. 用滑塊縮放ImageView
- 7. jQuery UI滑塊部件+ fancybox +縮放/縮放
- 8. jQueryJavaScript錯誤 - 丟失;之前聲明
- 9. 縮放和縮放
- 10. C#中滑塊縮放不正確#
- 11. 使用線性滑塊縮放圖像
- 12. jQuery和圖像滑塊/縮放效果
- 13. 使用滑塊縮放WKInterfaceMap(WKInterfaceSlider)
- 14. 兩塊代碼約縮放圖像
- 15. 通過out縮放Rmd中的地塊
- 16. Drupal,ImageCache模塊不能正確縮放
- 17. 實現縮放滑塊的QGraphicsView
- 18. 使用滑塊縮小和放大mapKit
- 19. GLSurfaceView縮放(PINCH縮放)
- 20. Gmaps4rails:縮放(不縮放)gmap
- 21. Flash AS3 - 在縮放和縮小時縮放播放器中的相機(縮放)
- 22. 啓用UIScrollView縮放重置縮放視圖轉換的縮放
- 23. 縮放
- 24. 2D縮放,縮放和平移
- 25. 縮放UIImageView和移動縮放
- 26. 用縮放手勢縮放UIImageView
- 27. Uiwebview在縮放和縮放後刷新
- 28. 檢測縮放iOS上的縮放
- 29. 縮放圖像到全寬和縮放
- 30. ios - 從當前比例縮放/縮放
java script!= javascript – balexandre 2010-04-20 13:20:45
是的,錯過了。謝謝。 – Ockonal 2010-04-20 13:39:08