BiOMECHANiK
07/07/2006, 13h41
Bonjour,
Voici une petite balise BBCode que nous nous sommes amusés à faire avec un pote, nous avons trouvé le script Javascript sur Internet : ici (http://www.webmonkey.com/06/08/index2a.html)
Et nous en avons fait une balise BBCode. Le but, un redimensionement de l'image afin de ne pas déformer le forum, et une jolie animation d'agrandissement lors du clic pour l'affichage dans les dimensions d'origine.
Donc rendez-vous dans votre AdminCP
Créer une nouvelle balise BBCode
******************************************
IMG FORMAT PAYSAGE
******************************************
Intitulé : imgb paysage
Balise : imgb
Code de remplacement :
<a href="{param}" class="livethumbnail"><img src="{param}" width="240" height="159" alt=""></a>
<script type="text/javascript">
<!--
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++)
if (links[i].className == 'livethumbnail')
{
var img = links[i].getElementsByTagName('img')[0];
img.state = 'small';
img.smallSrc = img.getAttribute('src');
img.smallWidth = parseInt(img.getAttribute('width'));
img.smallHeight = parseInt(img.getAttribute('height'));
img.largeSrc = links[i].getAttribute('href');
img.largeWidth = '500';
img.largeHeight = '332';
img.ratio = img.smallHeight / img.smallWidth;
links[i].onclick = scale;
}
function scale()
{
var img = this.getElementsByTagName('img')[0];
img.src = img.smallSrc;
if (! img.preloaded)
{
img.preloaded = new Image();
img.preloaded.src = img.largeSrc;
}
var interval = window.setInterval(scaleStep, 10);
return false;
function scaleStep()
{
var step = 10;
var width = parseInt(img.getAttribute('width'));
var height = parseInt(img.getAttribute('height'));
if (img.state == 'small')
{
width += step;
height += Math.floor(step * img.ratio);
img.setAttribute('width', width);
img.setAttribute('height', height);
if (width > img.largeWidth - step)
{
img.setAttribute('width', img.largeWidth);
img.setAttribute('height', img.largeHeight);
img.setAttribute('src', img.largeSrc);
window.clearInterval(interval);
img.state = 'large';
}
}
else
{
width -= step;
height -= Math.floor(step * img.ratio);
img.setAttribute('width', width);
img.setAttribute('height', height);
if (width < img.smallWidth + step)
{
img.setAttribute('width', img.smallWidth);
img.setAttribute('height', img.smallHeight);
img.src = img.smallSrc;
window.clearInterval(interval);
img.state = 'small';
}
}
}
}
-->
</script>
Exemple : url de votre image
Description : Reduit et agrandi une image au format paysage grâce à un fondu.
******************************************
IMG FORMAT PORTRAIT
******************************************
Intitulé : imgc portrait
Balise : imgc
Code de remplacement :
<a href="{param}" class="livethumbnail2"><img src="{param}" width="240" height="320" alt=""></a>
<script type="text/javascript">
<!--
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++)
if (links[i].className == 'livethumbnail2')
{
var img = links[i].getElementsByTagName('img')[0];
img.state = 'small';
img.smallSrc = img.getAttribute('src');
img.smallWidth = parseInt(img.getAttribute('width'));
img.smallHeight = parseInt(img.getAttribute('height'));
img.largeSrc = links[i].getAttribute('href');
img.largeWidth = '480';
img.largeHeight = '640';
img.ratio = img.smallHeight / img.smallWidth;
links[i].onclick = scale;
}
function scale()
{
var img = this.getElementsByTagName('img')[0];
img.src = img.smallSrc;
if (! img.preloaded)
{
img.preloaded = new Image();
img.preloaded.src = img.largeSrc;
}
var interval = window.setInterval(scaleStep, 10);
return false;
function scaleStep()
{
var step = 10;
var width = parseInt(img.getAttribute('width'));
var height = parseInt(img.getAttribute('height'));
if (img.state == 'small')
{
width += step;
height += Math.floor(step * img.ratio);
img.setAttribute('width', width);
img.setAttribute('height', height);
if (width > img.largeWidth - step)
{
img.setAttribute('width', img.largeWidth);
img.setAttribute('height', img.largeHeight);
img.setAttribute('src', img.largeSrc);
window.clearInterval(interval);
img.state = 'large';
}
}
else
{
width -= step;
height -= Math.floor(step * img.ratio);
img.setAttribute('width', width);
img.setAttribute('height', height);
if (width < img.smallWidth + step)
{
img.setAttribute('width', img.smallWidth);
img.setAttribute('height', img.smallHeight);
img.src = img.smallSrc;
window.clearInterval(interval);
img.state = 'small';
}
}
}
}
-->
</script> Exemple : url de votre image
Description : Reduit et agrandi une image au format portrait grâce à un fondu.
******************************************
Voilà c'est terminé, ca fonctionne aussi sous vBulletin 3.5 bien sûr.
Je pense qu'il est possible d'améliorer ce code, comme par exemple pour qu'il puisse prendre en compte les tailles d'origine de l'image et redimensionner en conscéquence.
Si vous avez la solution je suis prenneur ^^
Un grand merci à BUGG ;)
BiOMECHANIK. byby
Voici une petite balise BBCode que nous nous sommes amusés à faire avec un pote, nous avons trouvé le script Javascript sur Internet : ici (http://www.webmonkey.com/06/08/index2a.html)
Et nous en avons fait une balise BBCode. Le but, un redimensionement de l'image afin de ne pas déformer le forum, et une jolie animation d'agrandissement lors du clic pour l'affichage dans les dimensions d'origine.
Donc rendez-vous dans votre AdminCP
Créer une nouvelle balise BBCode
******************************************
IMG FORMAT PAYSAGE
******************************************
Intitulé : imgb paysage
Balise : imgb
Code de remplacement :
<a href="{param}" class="livethumbnail"><img src="{param}" width="240" height="159" alt=""></a>
<script type="text/javascript">
<!--
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++)
if (links[i].className == 'livethumbnail')
{
var img = links[i].getElementsByTagName('img')[0];
img.state = 'small';
img.smallSrc = img.getAttribute('src');
img.smallWidth = parseInt(img.getAttribute('width'));
img.smallHeight = parseInt(img.getAttribute('height'));
img.largeSrc = links[i].getAttribute('href');
img.largeWidth = '500';
img.largeHeight = '332';
img.ratio = img.smallHeight / img.smallWidth;
links[i].onclick = scale;
}
function scale()
{
var img = this.getElementsByTagName('img')[0];
img.src = img.smallSrc;
if (! img.preloaded)
{
img.preloaded = new Image();
img.preloaded.src = img.largeSrc;
}
var interval = window.setInterval(scaleStep, 10);
return false;
function scaleStep()
{
var step = 10;
var width = parseInt(img.getAttribute('width'));
var height = parseInt(img.getAttribute('height'));
if (img.state == 'small')
{
width += step;
height += Math.floor(step * img.ratio);
img.setAttribute('width', width);
img.setAttribute('height', height);
if (width > img.largeWidth - step)
{
img.setAttribute('width', img.largeWidth);
img.setAttribute('height', img.largeHeight);
img.setAttribute('src', img.largeSrc);
window.clearInterval(interval);
img.state = 'large';
}
}
else
{
width -= step;
height -= Math.floor(step * img.ratio);
img.setAttribute('width', width);
img.setAttribute('height', height);
if (width < img.smallWidth + step)
{
img.setAttribute('width', img.smallWidth);
img.setAttribute('height', img.smallHeight);
img.src = img.smallSrc;
window.clearInterval(interval);
img.state = 'small';
}
}
}
}
-->
</script>
Exemple : url de votre image
Description : Reduit et agrandi une image au format paysage grâce à un fondu.
******************************************
IMG FORMAT PORTRAIT
******************************************
Intitulé : imgc portrait
Balise : imgc
Code de remplacement :
<a href="{param}" class="livethumbnail2"><img src="{param}" width="240" height="320" alt=""></a>
<script type="text/javascript">
<!--
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++)
if (links[i].className == 'livethumbnail2')
{
var img = links[i].getElementsByTagName('img')[0];
img.state = 'small';
img.smallSrc = img.getAttribute('src');
img.smallWidth = parseInt(img.getAttribute('width'));
img.smallHeight = parseInt(img.getAttribute('height'));
img.largeSrc = links[i].getAttribute('href');
img.largeWidth = '480';
img.largeHeight = '640';
img.ratio = img.smallHeight / img.smallWidth;
links[i].onclick = scale;
}
function scale()
{
var img = this.getElementsByTagName('img')[0];
img.src = img.smallSrc;
if (! img.preloaded)
{
img.preloaded = new Image();
img.preloaded.src = img.largeSrc;
}
var interval = window.setInterval(scaleStep, 10);
return false;
function scaleStep()
{
var step = 10;
var width = parseInt(img.getAttribute('width'));
var height = parseInt(img.getAttribute('height'));
if (img.state == 'small')
{
width += step;
height += Math.floor(step * img.ratio);
img.setAttribute('width', width);
img.setAttribute('height', height);
if (width > img.largeWidth - step)
{
img.setAttribute('width', img.largeWidth);
img.setAttribute('height', img.largeHeight);
img.setAttribute('src', img.largeSrc);
window.clearInterval(interval);
img.state = 'large';
}
}
else
{
width -= step;
height -= Math.floor(step * img.ratio);
img.setAttribute('width', width);
img.setAttribute('height', height);
if (width < img.smallWidth + step)
{
img.setAttribute('width', img.smallWidth);
img.setAttribute('height', img.smallHeight);
img.src = img.smallSrc;
window.clearInterval(interval);
img.state = 'small';
}
}
}
}
-->
</script> Exemple : url de votre image
Description : Reduit et agrandi une image au format portrait grâce à un fondu.
******************************************
Voilà c'est terminé, ca fonctionne aussi sous vBulletin 3.5 bien sûr.
Je pense qu'il est possible d'améliorer ce code, comme par exemple pour qu'il puisse prendre en compte les tailles d'origine de l'image et redimensionner en conscéquence.
Si vous avez la solution je suis prenneur ^^
Un grand merci à BUGG ;)
BiOMECHANIK. byby