V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
thonatos
V2EX  ›  分享创造

MT-Libraries/MT-Retina.js

  •  
  •   thonatos ·
    thonatos · 2015-11-17 15:30:29 +08:00 · 1777 次点击
    这是一个创建于 3076 天前的主题,其中的信息可能已经有所发展或是发生改变。

    MT-Retina.js

    serve high-resolution images to devices with retina displays.

    Usage

    add lib & config

    <script src="dist/retina.js"></script>
    <script src="src/retina-config.js"></script>
    

    set tags

    <img 
        data-retina-url="assets/images/test/retina.png" 
        data-img-type="normal" 
        data-img-lang="en" 
        alt="img">
    

    add assets

    > tree -L 4                                           
    .
    └── images
        └── test
            ├── en
            │   ├── [email protected]
            │   └── [email protected]
            ├── [email protected]
            └── [email protected]
    
    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

    License

    The MIT License (MIT)

    Copyright (c) 2015 Magic Term Libraries

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2677 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 04:14 · PVG 12:14 · LAX 21:14 · JFK 00:14
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.