A cópia do código é a seguinte:
<div id = artigo> <img src = "/down/js/imagens/12498880470.jpg"/> </div>
<script type = "text/javascript">
// escala a imagem para o tamanho apropriado
função redizeimages ()
{
Var Myimg, Oldwidth, OldHeight;
var maxwidth = 550;
var maxHeight = 880
var iMgs = document.getElementById ('artigo'). getElementsByTagName ('img');
para (i = 0; i <imgs.length; i ++) {
myimg = imgs [i];
if (myimg.width> myimg.Height)
{
if (myimg.width> maxwidth)
{
OldWidth = myimg.width;
myimg.Height = myimg.Height * (MaxWidth/OldWidth);
myimg.width = maxWidth;
}
}outro{
if (myimg.Height> maxHeight)
{
OldHeight = myimg.Height;
myimg.width = myimg.width * (maxHeight/OldHeight);
myimg.Height = maxHeight;
}
}
}
}
// escala a imagem para o tamanho apropriado
REDIMEIDAIMAGES ();
</script>
Significa controlar o tamanho da imagem na área especificada, caso contrário, algumas imagens de publicidade maiores também se deformam.
O código de controle de imagem usado por wulin.com:
A cópia do código é a seguinte:
função controlImg (ele, w, h) {
var c = ele.getElementsByTagName ("img");
for (var i = 0; i <c.Length; i ++) {
var w0 = c [i] .clientwidth, h0 = c [i] .clientHeight;
var T1 = W0/W, T2 = H0/H;
if (t1> 1 || t2> 1 || w0> = 600) {
C [i] .Width = Math.floor (W0/(T1> T2? T1: T2));
C [i] .Height = Math.floor (H0/(T1> T2? T1: T2));
if (document.all) {
c [i] .outerhtml = '<a href = "'+c [i] .src+'" target = "_ blank">'+c [i] .outerhtml+'</a>'
}
outro{
C [i] .title = "Abra a imagem na nova janela";
c [i] .OnClick = function (e) {window.open (this.src)}
}
}
}
}
ELE é a área especificada, W é a largura máxima e será reduzida se for maior que isso. H é a altura máxima.