我有一個jQuery函數,縮放圖片,使最大的測量是350px,無論原始大小。動態jQuery函數與PHP
jQuery的:從我的數據庫使用PHP循環
function Scale(){
var img = new Image();
img.onload = function() {
alert('Orignal width:'+img.width+', height:'+img.height);
var width, height;
if (img.width > img.height) {
width = (img.width > 350 ? 350 : img.width);
height = img.height * (350/img.width);
} else {
height = (img.height > 350 ? 350 : img.height);
width = img.width * (350/img.height);
}
img.width=width;
img.height=height;
$("#img-holder").append(img);
}
img.src = "picture.jpg"
}
我檢索圖片鏈接。
PHP:
$q = "SELECT * FROM `items`";
$row = mysqli_query($con, $q) or die(mysqli_error());
while($r = mysqli_fetch_assoc($row))
{
//do stuff
}
圖片鏈接將被存儲爲每次循環運行$r['picture']
。
我的問題:我該如何爲循環檢索的每張圖片運行jQuery腳本?
你知道嗎有一個[CSS屬性](https://developer.mozilla.org/en-US/docs/CSS/max-width)? – Blazemonger 2013-04-11 14:57:35
該CSS屬性是否保持圖片的比例? – 2013-04-11 15:01:59
取決於你如何做,是的。提交了一個答案。 – Blazemonger 2013-04-11 15:02:53