MT-Retina.js
Github: MT-Retina.js
serve high-resolution images to devices with retina displays.
之前月大总管写的为高分屏提供不同分辨率图像支持的插件,需求变动,增加了语言支持。
<script src="dist/retina.js"></script> <script src="src/retina-config.js"></script>
<img data-retina-url="assets/images/test/retina.png" data-img-type="normal" data-img-lang="en" alt="img">
> tree -L 4 . └── images └── test ├── en │ ├── retina@1x.png │ └── retina@2x.png ├── retina@1x.png └── retina@2x.png 3 directories, 4 files
Customize the rules for assets can be found in the retina-config.js .
// define filters Retina.setFilters({ 'normal': function (url, base, ratio, lang) { var result, prefix = '', pieces = url.split('/'); // Add language support if (lang) { prefix = lang + '/'; } var _postfix = pieces[pieces.length - 1].split('.'); // Concat File Path String pieces[pieces.length - 1] = prefix + _postfix[0] + '@' + ratio.param + '.' + _postfix[1]; result = pieces.join('/'); return result; }, 'svg': function (url, base, ratio, lang) { return url; } });
modifyRetinaImg(target,src); Retina.retinaUpdate();