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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
| <!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="Author" content="Daniel Hagnoul">
<title>Forum jQuery</title>
<style>
/* Base */
div,p,h1,h2,h3,h4,h5,h6,ul,ol,dl,form,table,img {margin:0px; padding:0px; }
body {background-color:#dcdcdc; color:#000000; font-family:sans-serif; font-size:medium; font-style:normal; font-weight:normal; line-height:normal; letter-spacing:normal; }
h1,h2,h3,h4,h5 {font-family:serif; padding:6px; }
img {border:none; }
h1 {font-size:2em; text-shadow: 4px 4px 4px #bbbbbb; text-align:center; }
p {padding:6px; }
ul,ol,dl {list-style:none; padding-left:6px; padding-top:6px; }
li {padding-bottom:6px; }
label {display:block; }
input {width:250px; }
input[type="button"] {width:auto; }
input[required] {border-right:3px solid orange; }
td {padding:3px; }
.conteneur {width:95%; min-width:800px; min-height:400px; margin:12px auto; background-color:#FFFFFF; color:#000000; border:1px solid #666666; }
/* Plugin */
div {float:left; border:1px dotted grey; overflow:hidden; word-wrap:break-word; padding:6px;}
.classDiv1 {width:100px; max-width:100px; height:100px; max-height:100px; }
.classDiv2 {width:150px; max-width:150px; height:100px; max-height:100px; }
.classDiv3 {width:200px; max-width:200px; height:100px; max-height:100px; }
.classDiv4 {width:250px; max-width:250px; height:400px; max-height:400px; }
.classDiv5 {width:350px; max-width:350px; height:400px; max-height:400px; }
.classDiv6 {width:450px; max-width:450px; height:400px; max-height:400px; }
.classDiv7 {width:550px; max-width:550px; height:400px; max-height:400px; }
.classDiv8 {width:350px; max-width:350px; height:400px; max-height:400px; }
.classDiv9 {width:150px; max-width:150px; height:400px; max-height:400px; }
</style>
</head>
<body>
<h1>Forum jQuery</h1>
<section class="conteneur">
<div class="classDiv1">
<img class="dvjhClassImg" src="http://danielhagnoul.developpez.com/images/twitter.png" data-ratio="1.00"/>
</div>
<div class="classDiv2">
<img class="dvjhClassImg" src="http://danielhagnoul.developpez.com/images/Noël.jpg" data-ratio="0.6728"/>
</div>
<div class="classDiv3">
<img class="dvjhClassImg" src="http://danielhagnoul.developpez.com/images/avatarDVJH.jpg" data-ratio="1.00"/>
</div>
<p style="clear:both;"> </p>
<div class="classDiv4">
<img class="dvjhClassImg" src="http://danielhagnoul.developpez.com/images/Noël.jpg" data-ratio="0.6728"/>
</div>
<div class="classDiv5">
<img class="dvjhClassImg" src="http://danielhagnoul.developpez.com/images/imageTest.png" data-ratio="1.35"/>
</div>
<div class="classDiv6">
<img class="dvjhClassImg" src="http://danielhagnoul.developpez.com/images/rotating.gif" data-ratio="0.9638"/>
</div>
<p style="clear:both;"> </p>
<div class="classDiv7">
<img class="dvjhClassImg" src="http://danielhagnoul.developpez.com/images/badge.jpg" data-ratio="1.4848"/>
</div>
<div class="classDiv8">
<img class="dvjhClassImg" src="http://danielhagnoul.developpez.com/images/voeux.gif" data-ratio="4.14"/>
</div>
<div class="classDiv9">
<img class="dvjhClassImg" src="http://danielhagnoul.developpez.com/images/badge.jpg" data-ratio="1.4848"/>
</div>
<p style="clear:both;"> </p>
</section>
<footer itemscope itemtype="http://data-vocabulary.org/Person">
<time datetime="2011-04-29T22:05:00.000+02:00" pubdate>2011-04-29</time> <span itemprop="name">Daniel Hagnoul</span> <a href="http://www.developpez.net/forums/u285162/danielhagnoul/" itemprop="url">@danielhagnoul</a>
</footer>
<script charset="utf-8" src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<script>
/*
* Daniel Hagnoul
* Plugin dvjhImgRatio
* Code v1.1.0 du 2011-04-29
* v1.0.0 du 2011-04-25
* ------------------------------------------
* Usage : $(".dvjhClassImg").dvjhImgRatio();
*
* Pour un padding de 6px et une bordure de 1px :
* $(".dvjhClassImg").dvjhImgRatio({
* padding: [6, 6, 6, 6]
* });
* ------------------------------------------
* Options par défaut :
* border: [1, 1, 1, 1], // [top, right, bottom, left], l'unité est le pixel exclusivement
* padding: [0, 0, 0, 0] // [top, right, bottom, left], l'unité est le pixel exclusivement
*/
(function($){
$.fn.dvjhImgRatio = function(options){
var opts = $.extend(true, {}, $.fn.dvjhImgRatio.defaults, options);
return this.each(function(i, item){
var photo = $(item),
ratio = photo.data("ratio"),
photoParent = photo.parent(),
photoParentWidth = photoParent.innerWidth() - opts.border[1] - opts.border[3] - opts.padding[1] - opts.padding[3],
photoParentHeight = photoParent.innerHeight() - opts.border[0] - opts.border[2] - opts.padding[0] - opts.padding[2],
w = photoParentWidth,
h = w/ratio;
if (h > photoParentHeight){
h = photoParentHeight;
w = h*ratio;
}
// debug
/*
console.log("i = " + (i).toFixed(0), " | w = " + (w).toFixed(2),
" | h = " + (h).toFixed(2),
" | w/h = " + (w/h).toFixed(2), " | ratio = " + ratio);
*/
photo.css({width: w, height: h});
});
};
$.fn.dvjhImgRatio.defaults = {
border: [1, 1, 1, 1], // [top, right, bottom, left], l'unité est le pixel exclusivement
padding: [0, 0, 0, 0] // [top, right, bottom, left], l'unité est le pixel exclusivement
};
})(jQuery);
$(function(){
/*
* Pour des divisions ayant une bordure
* de 1 px et un padding de 6px.
*/
$(".dvjhClassImg").dvjhImgRatio({
padding: [6, 6, 6, 6] // [top, right, bottom, left], l'unité est le pixel exclusivement
});
});
</script>
</body>
</html> |
Partager