La copia del código es la siguiente:
<div id = artículo> <img src = "/down/js/images/12498880470.jpg"/> </div>
<script type = "text/javaScript">
// Escala la imagen al tamaño apropiado
función resizeImages ()
{
Var Myimg, Oldwidth, Oldheight;
var maxwidth = 550;
var maxheight = 880
var imgs = document.getElementById ('Artículo'). 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;
}
}demás{
if (myimg.height> maxheight)
{
Oldheight = myimg.Height;
myimg.width = myimg.width * (maxheight/oldheight);
myimg.height = maxHeight;
}
}
}
}
// Escala la imagen al tamaño apropiado
ResizeImages ();
</script>
Significa controlar el tamaño de la imagen en el área especificada, de lo contrario, algunas imágenes publicitarias más grandes también se deformarán.
El código de control de la imagen utilizado por wulin.com:
La copia del código es la siguiente:
function Controlimg (ELE, W, H) {
var c = ele.getElementsBytagName ("img");
para (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 = "_ en blanco">'+c [i] .outerhtml+'/a> '
}
demás{
c [i] .title = "imagen abierta en la nueva ventana";
c [i] .onclick = function (e) {window.open (this.src)}
}
}
}
}
Ele es el área especificada, W es el ancho máximo y se reducirá si es mayor que esto. H es la altura máxima.