我有这样的代码:的Javascript调整每个图像加载
while ($row = mysql_fetch_assoc($result1)) {
echo "
<a href='#'id='VV".$row['id']."'>
<p>".$row['title']."</p>
<p>".$row['date']."</p>
<img onload='scale()' id='II".$row['id']."' src='../res/videos/img/".$row['img']."'/>
</a>
<script type='text/javascript'>
function scale(){
var image = document.getElementById('II".$row['id']."');
var width = image.width;
var height = image.height;
if (width > 150) {
image.style.width = '150px';
image.style.height = 'auto';
}
width = image.width;
height = image.height;
if (height > 80) {
image.style.height = '80px';
image.style.width = 'auto';
}
width = image.width;
height = image.height;
}
VV".$row['id'].".onclick = function() {
var Result = '".$row['id']."';
location.href='loged.php?Result=' + Result;
}
</script>
";
}?>
我想调整大小功能加载的每个图像上调用,但最后的图像加载时,它被调用,只有最后一个图像生效。我应该改变什么?
在浏览器中你不应该调整图像。浏览器会渲染内容较慢,设计看起来很糟糕。 – machineaddict 2012-02-02 17:36:28
我正在缩放它们... – Liukas 2012-02-03 09:08:34