资讯专栏INFORMATION COLUMN

MT-Retina.js

XUI / 690人阅读

摘要:之前月大总管写的为高分屏提供不同分辨率图像支持的插件,需求变动,增加了语言支持。

MT-Retina.js

Github: MT-Retina.js

serve high-resolution images to devices with retina displays.

之前月大总管写的为高分屏提供不同分辨率图像支持的插件,需求变动,增加了语言支持。

Usage add lib & config

  
set tags
img    
add assets
> tree -L 4                                           
.
└── images
    └── test
        ├── en
        │   ├── retina@1x.png
        │   └── retina@2x.png
        ├── retina@1x.png
        └── retina@2x.png

3 directories, 4 files
Config customize

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()
modifyRetinaImg(target,src);
Retina.retinaUpdate();
About

@Author Max

@Revised Thonatos.Yang

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/86229.html

相关文章

发表评论

0条评论

最新活动
阅读需要支付1元查看
<