我有一个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