adding @2x to src above certain resolution on none retina devices

后端 未结 1 1634
深忆病人
深忆病人 2021-01-28 13:58

I use retinaJS on my site to serve @2x images on retina devices.

I would also like to be able to use jQuery to server @2x images on none retina - large screen desktop de

相关标签:
1条回答
  • 2021-01-28 14:30

    This should do it, regardless of the extension length, so long as the .xxx is the final part of the image URL:

    $('.bodycontent img').prop('src', function(_, src) {
        src = src.replace(/@2x\./, '.');         // strip if it's already there
        return src.replace(/(\.\w+$)/, '@2x$1');
    });
    
    0 讨论(0)
提交回复
热议问题