Script House integration article, welcome to reprint.
If you need to introduce external Js, you need to refresh to execute ]
The following is used The method of implementing css expression will increase the load on the client. It is recommended to use js's
. Suppose there is a div with an id of test. How to control whether the pictures inside it will be stretched?
Just define the CSS as follows:
The code is as follows:
<script> //============================== function 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){ 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" title="在新窗口打开图片">'+c[i].outerHTML+'' } else{ c[i].title="在新窗口打开图片"; c[i].onclick=function(e){window.open(this.src)} } } } } window.onload=function(){ controlImg(document.getElementById("dxy"),300,300); } </script> , the width of the picture will not exceed 600, the height will not exceed 450, and will be reduced according to the original proportion!