在回答:
唉,JavaScript的根本不能夠提取的屬性你需要這樣做的圖像。但是,可能會有HTML元素的形式與一些服務器端腳本相結合的救贖。 ...
< ? (open php)
$large_image = 'path/to/large_image';
$full_w = imagesx($large_image);
$full_h = imagesy($large_image);
(close php) ? >
這可以在Javascript中完成,只是谷歌了一下:
var newimage = new Image();
newimage.src = document.getElementById('background').src;
var height = newimage.height;
var width = newimage.width;
這產生從現有的一個新的圖像和Java腳本的原始捕獲這樣原始圖像的高度和寬度屬性(不是以id'ed作爲背景的)
回答:
文檔的圖像對象的寬度/高度屬性是隻讀的。但是,如果你可以改變它們,你只會擠壓框架,而不是像你想要的那樣剪掉框架。您想要的圖像處理類型不能用客戶端JavaScript來完成。我建議在服務器上剪切圖像,或者在圖像上疊加一個div以隱藏不希望顯示的部分。
...
var newimage = new Image();
newimage.src = document.getElementById('background').src;
var height = newimage.height;
var width = newimage.width;
newimage.style.height = '200px';
newimage.style.width = '200px';
newimage.height = '200px';
newimage.width = '200px';
,如果想:
newimage.setAttribute('height','200px');
的一倍newimage.style.height並且需要在某些情況下,爲了確保newimage.height一個IE會及時瞭解圖像的大小調整(您將立即渲染該內容,並且內部IE處理速度太慢)
感謝上述腳本我修改並實施了http://morethanvoice.net/m1/reader13.php(鼠標右鍵菜單... mouseover zoom lent),即使在IE中也是正確的,但是你會注意到鼠標移動圖像處理對於舊式IE來說太快了,只能渲染一次圖像的位置。無論如何,任何好主意都是值得歡迎的。
感謝大家的關注,希望上面的代碼可以幫助別人......
克勞迪奧·Klemp http://morethanvoice.net/m1/reader13.php
非常酷。幾乎立即工作。只有你的代碼的問題是,當它應該使用'y'時,img.style.top使用'x'參數,左邊是同樣的東西。除此之外,工作就像一個魅力! – 2009-01-26 21:35:40