コードコピーは次のとおりです。
<div id = article> <img src = "/down/js/images/124988880470.jpg"/> </div>
<script type = "text/javascript">
//写真を適切なサイズにスケーリングします
関数resizeImages()
{
var myimg、oldwidth、oldheight;
var maxwidth = 550;
var maxheight = 880
var imgs = document.getElementByid( 'article')。
for(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;
}
}それ以外{
if(myimg.height> maxheight)
{
oldheight = myimg.height;
myimg.width = myimg.width *(maxheight/oldheight);
myimg.height = maxheight;
}
}
}
}
//写真を適切なサイズにスケーリングします
resizeImages();
</script>
これは、指定された領域の画像のサイズを制御することを意味します。そうしないと、いくつかの大きな広告画像も変形します。
wulin.comが使用する画像制御コード:
コードコピーは次のとおりです。
関数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+'"ターゲット= "_ blank">'+c [i] .outerhtml+'</a>'
}
それ以外{
c [i] .title = "新しいウィンドウで開く画像";
c [i] .onclick = function(e){window.open(this.src)}
}
}
}
}
ELEは指定された領域であり、Wは最大幅であり、これよりも大きい場合は減少します。 Hは最大高さです。