media queries - jquery image resize
Hi Guys,
I got inspired by @ppk's post about media queries and javascript plus everyone elses media queries blogs and thought how about adding a bit a of code so that if the device is a certain size (480px wide perhaps) then add '-mobile' to the images so that it'll download smaller images for the web.
I posted it on stackoverflow with two bits of code I found that needed almagamating into one and @craftedpixels came to my rescue with this code -
$(document).ready(function() {
if ((screen.width<=960) && (screen.height<=640)) {
$
("img").attr("src", $("img").attr("src").replace(/([^.]*)\.(.*)/, "$1-iphone.$2"));
}
});
Works for me on iphone 3g.
what do you reckon guys?
regards
Stu
I'm not the greatest, I never will be, but getting there one code at a time