我有這樣的代碼:的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