5
A
回答
2
@Aron的解決方案是可以的,但它具有一定的侷限性:文檔流程中不能有圖像。
我的解決方案實際上創建了一個絕對定位的圖像克隆,並將其顯示在原始圖像的頂部。它使用.offset()
來計算原始圖像的絕對位置。
這種方法的缺點是,如果文檔流量的變化(如調整大小客戶端窗口時),絕對定位元件保持在舊的位置這一點。這取決於你的頁面佈局,如果你可以使用這種方法或不。
單擊我的演示中的圖像切換效果。 http://jsfiddle.net/Xhchp/3/
HTML:
<p>Some random text.</p>
<p>More blah. <img id="someImage" src="http://upload.wikimedia.org/wikipedia/commons/thumb/1/16/Deletion_icon.svg/600px-Deletion_icon.svg.png"/> More blah.</p>
<p>Some random text.</p>
CSS:
#someImage { width:32px; height:32px; }
的javascript:
function ZoomIn(){
var p = $(this).offset();
var w = $(this).width();
var h = $(this).height();
var $clone = $(this).clone();
$clone.css({
position: "absolute",
left: p.left + "px",
top: p.top + "px",
"z-index": 2
}).appendTo('body');
$clone.data("origWidth",w);
$clone.data("origHeight",h);
$clone.data("origTop",p.top);
$clone.data("origLeft",p.left);
$clone.animate({
top: "-=" + Math.floor(h * 0.5),
left: "-=" + Math.floor(w * 0.5),
width: Math.floor(w * 2),
height: Math.floor(h * 2)
},function(){
});
$clone.click(ZoomOut);
}
function ZoomOut(){
var w = $(this).data("origWidth");
var h = $(this).data("origHeight");
var t = $(this).data("origTop");
var l = $(this).data("origLeft");
$(this).animate({
top: t,
left: l,
width: w,
height: h
},function(){
$(this).remove();
});
}
$(function(){
$('img').click(ZoomIn);
});
10
這應該不是太難:
// increase factor
var factor = 2;
$('#foo').click(function() {
$(this).animate({
top: '-=' + $(this).height()/factor,
left: '-=' + $(this).width()/factor,
width: $(this).width() * factor
});
});
這是如何實現的:
- 圖像的尺寸以一定的比例增加。在這種情況下,這是
* 2
,但我可以想象你想做一些聰明的事情,並且有一個上限左右。 - 隨着當前尺寸除以增加因子,圖像頂部和左側偏移量減小。
2
如果我的理解沒錯,here is what you want。
我用position: absolute
顯示大圖像,那麼您的佈局不會受到被調整大小的圖像的影響。如果您對此解決方案有疑問,請在這裏發表評論。
+0
你怎麼會去toggeling這個功能呢? – Studiostefan 2012-07-08 18:29:13
相關問題
- 1. 調整尺寸圖像
- 2. Node.js調整圖像尺寸
- 3. 調整圖像尺寸PHP
- 4. 使用php調整圖像尺寸
- 5. 使用Graphics.DrawImage調整圖像尺寸結果尺寸調整不正確
- 6. 通過javascript調整圖像大小或調整圖像尺寸
- 7. 使用PHP5和JQuery調整圖像尺寸
- 8. 使用jQuery動畫將圖像調整爲原始尺寸
- 9. Sitecore的8 RTE圖像尺寸調整
- 10. 調整SVG背景圖像的尺寸
- 11. Graphics32:調整大量圖像的尺寸
- 12. Android根據設備的屏幕尺寸調整圖像尺寸
- 13. 根據圖像尺寸調整ImageViews的尺寸
- 14. JQuery - 試圖調整Fancybox的尺寸
- 15. 調整圖像尺寸iPhone SDK
- 16. 當屏幕尺寸減小時自動調整圖像尺寸
- 17. 將圖像調整爲更小尺寸
- 18. 使用Powerpoint vba調整圖片尺寸
- 19. 根據jQuery中的尺寸調整每個圖像的大小
- 20. woocommerce使用全尺寸圖像,調整大小,縮略圖
- 21. 使用as3調整Flex中的圖像的尺寸
- 22. 使用Paperclip調整默認圖像的尺寸
- 23. 僅使用Tkinter調整pgm圖像的尺寸
- 24. 使用低質量的Codeigniter調整圖像尺寸
- 25. 使用php調整圖像的尺寸或用strech進行調整?
- 26. 不斷調整google地圖的尺寸
- 27. 用codeigniter調整圖片的尺寸
- 28. 調整JIT圖形的畫布尺寸
- 29. jquery圖像替換屏幕尺寸調整
- 30. 圖像調整大小會產生原始尺寸的圖像
我沒有測試過這一點,所以這仍將是一個評論,但你能不能改變動畫的寬度/高度,然後頂部/左側,頂部/左側是寬度/高度變化的一半。 – Robert 2011-05-03 14:09:27