La copie de code est la suivante:
<div id = article> <img src = "/ down / js / images / 12498880470.jpg" /> </div>
<script type = "text / javascript">
// Échelle l'image à la taille appropriée
Fonction ResizeImages ()
{
Var Myimg, vieillesse, oldheight;
var maxwidth = 550;
var maxheight = 880
var imgs = document.getElementById («article»). GetElementsByTagName («img»);
pour (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;
}
}autre{
if (myimg.height> maxheight)
{
OldHeight = Myimg.Height;
myimg.width = myimg.width * (maxheight / oldheight);
myimg.height = maxheight;
}
}
}
}
// Échelle l'image à la taille appropriée
RedimensiMages ();
</cript>
Cela signifie contrôler la taille de l'image dans la zone spécifiée, sinon certaines images publicitaires plus grandes se déformeront également.
Le code de contrôle d'image utilisé par wulin.com:
La copie de code est la suivante:
fonction ControlImg (ele, w, h) {
var c = ele.getElementsByTagName ("img");
pour (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 + '" cible = "_ blanc">' + c [i] .outerhtml + '</a>'
}
autre{
c [i] .title = "Ouvrir l'image dans une nouvelle fenêtre";
c [i] .onclick = fonction (e) {window.open (this.src)}
}
}
}
}
ELE est la zone spécifiée, W est la largeur maximale, et elle sera réduite si elle est supérieure à celle-ci. H est la hauteur maximale.