Voici un petit bout de code jQuery bien utile pour convertir tout lien pointant vers une image à une miniature de celle-ci pointant vers l’originale. Très utile pour un blogue ou un forum!
//set image max width
imgMaxWidth = 150;
//define regex pattern to detect images
regexImg = /^http:\/\/(.)+\.(jpg|jpeg|gif|png)$/gi;
//parse links
$('DIV.activity a').each(function(){
//if a link points to an image
if($(this).attr('href').match(regexImg)) {
//add classes
$(this).addClass('fetchedImgLink');
//edit target
$(this).attr('target', '_blank');
//show image instead of text
$(this).html("< img class='fetchedImg' src='" + $(this).attr('href') + "' />");
//check for size
var currentImg = $(this).find('img');
var iw = currentImg.width();
var ih = currentImg.height();
var ratio = (ih!=0) ? iw/ih : 1;
//resize if needed
if(iw > imgMaxWidth) {
currentImg.width(imgMaxWidth);
currentImg.height(ih - ((iw-imgMaxWidth) / ratio));
}
}
});
JQuery ou MooTools, telle est la question!
C’est que je suis tombé sur ça et sur ça… et j’avoue que je ne sais plus trop quoi penser.
Est-ce que ça se vaut à ce point comme librairies? Parce que j’ai tenté d’installer les deux sur une même page hier et 1) c’est beaucoup trop lourd; 2) ça joue du coude; 3) ça devient passablement instable quand ça ne plante pas totalement.
blogue / Catégories
- Annonces (4)
- Cuisine (1)
- Médias (6)
- Personnel (6)
- Sport (6)
- Web (13)
- Accessibilité (4)
- Publicité (7)
- Réseau Sociaux (12)
- SEO (1)
Twitter @Molaram
Liens partagés
- Flickr: NASA on The Commons' Photostream
- Recognize The Bloggers
- Leaked: NHL guidelines for how teams credential bloggers
- HASSANCHOP (slow mo brick break) (pic)
- KeyCase iPad Folio - Une housse avec clavier intégré
- NHL teams want bloggers banned from visitors' locker rooms
- LEGO FACEBOOK
- [rédacteur invité] Pourquoi Facebook est contraint de brader ses tarifs publicitaires
- Une «superstition» technique annonce-t-elle l’imminence d’un krach boursier? - bourse - LesAffaires.com
- The 15 Cheapest Movies That Went On To Become Cult Classics | KoldCast TV - News Blog
Mots-clefs
appartement
blogosphère
blogues
branchez-vous
buddypress
canadiens
cinéma
design
délire
Développement
eBay
entraînement
facebook
fanatique
fanatiqueca
google
hockey
humour
image
internet
iphone
maths
molson
musique
nostalgie
personnel
PHP
politique
pub
radio
société
spam
sport
techno
technologie
twitter
télé
télévision
utopie
viral
voyage
Web
Wordpress
youtube
yulblog
Ailleurs
- 100% Hockey
- AccesOWeb
- Alsacréations
- Canadiens de Montréal
- Carl Charest
- Carl-Frédéric De Celles
- Chrystian Guy
- Debbie Rouleau
- Dominic Arpin
- Eric Baillargeon
- Famille Enfants Parents
- Goudaille
- Histoires de Geek
- Il Blogue
- Influenceur – Blogue Tendance
- Martin Petit
- Michel Dumais
- Nicolas Langelier
- Patrick Lagacé
- PhotosMax
- Samuel Parent
- Sébstien Goulet
- Sportnographe
- Stéphane Guérin
- Stéphane Jose
- Tchuvak’s Life
- Yannick Manuri
- Ze Canada
