jquery - adding @2x to src above certain resolution on none retina devices -
jquery - adding @2x to src above certain resolution on none retina devices -
i utilize retinajs on site serve @2x images on retina devices.
i able utilize jquery server @2x images on none retina - big screen desktop devices. if screen resolution above 1330px want able add together @2x end of filename straight before file suffix/extension.
can suggest how might this?
my theory find images within target div (e.g. .bodycontent) , count 4 characters attribute src , add together in @2x src
e.g.
example.jpg becomes example@2c.jpg , chickens.png becomes chickens@2x.png
this of course of study works on files 3 leter extensions - e.g. png / jpg - ok never phone call files jpeg example...
i need code apply images found in target div.
any help?
cheers
this function called on every resize check @2x needs applied - how can add together code check see if @2x included in attr src , not perform if @2x?
this should it, regardless of extension length, long .xxx final part of image url:
$('.bodycontent img').prop('src', function(_, src) { src = src.replace(/@2x\./, '.'); // strip if it's there homecoming src.replace(/(\.\w+$)/, '@2x$1'); }); jquery retina
Comments
Post a Comment