1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| <!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function addEvent( obj_, event_, func_, mode_){
if( obj_.addEventListener){
obj_.addEventListener( event_, func_, mode_? mode_:false);
}
else{
obj_.attachEvent( 'on'+event_, func_);
}
}
function ratioImage(urlImage,largeurImg, conteneur){
var photo = new Image();
photo.src = urlImage;
photo.onload = function(){
var photoWidth=photo.width;
var photoHeight=photo.height;
var ratio=(Math.round((largeurImg/photoWidth)*100))/100;
this.width = photoWidth*ratio;
this.height= photoHeight*ratio;
document.getElementById(conteneur).appendChild(photo);
};
}
addEvent( window, "load", function(){
ratioImage('http://www.clickonmylinks.fr/wp-content/images/singe1.jpg',100,'plip');
ratioImage('http://www.clickonmylinks.fr/wp-content/images/singe1.jpg',100,'plop');
}, false);
</script>
</head>
<body>
blablabla
<div id="plip"></div>
bliblibli
<div id="plop"></div>
</body>
</html> |
Partager