Coder Social home page Coder Social logo

tylercraft / jquery-retina Goto Github PK

View Code? Open in Web Editor NEW
153.0 153.0 16.0 20.42 MB

A jQuery plugin for swapping out images with images scaled for retina displays

Home Page: http://retina.tylercraft.com/

License: GNU General Public License v2.0

JavaScript 89.22% CSS 8.22% HTML 2.56%

jquery-retina's People

Contributors

coliff avatar mtmail avatar tylercraft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery-retina's Issues

What about responsive images

If the image has a max-width of 100% and the original is 300 px wide by 200px and it floats in the text, then when it's swapped it will be 600 px by 400 px and it won't wrap any more. What can be done about this? Anyway for the another tag like (this is made up) data-width="300" data-height="200" so it scales down to that size and then is also responsive that is the max width is 300px and the height is variable. I'm getting very confused with this retina stuff.

Idea: update script this to be a polyfill for srcset

If the 'jQuery-Retina' script was updated to read the x2 image location from the srcset attribute instead it would work as a great polyfill for srcset.

So jQuery retina markup would read:
< img src="/image-x1.png" srcset="/image-x2.png 2x" >

and read/display the image-x2.png from the scrset attribute. This way we can get rid of the data-retina attribute from our markup and modern browsers like Chrome (from v34 onwards) would use the srcset attribute.

Ref: http://blog.chromium.org/2014/02/chrome-34-responsive-images-and_9316.html

idea: make it easier to disable retina on mobile

In some cases it makes sense to load retina images on retina devices, but only if they aren't mobile devices. In a responsive design, sometimes the non-retina version is already big enough to appear "retina" on mobile screens, and you don't want users on a cell internet connection to have to download too much.

I currently can work around it with some copy/pasting, but you could add an option or two that could make this easier for others. There could be a direct enabledForMobile setting, or a more generic retinaEnabledCallback.

// img.retina: load retina version if on retina device
$('img.retina').retina({ suffix: '@2x' });

// img.retina-large: load retina version only if on tablet/desktop
// (for when you don't want mobile to have to download huge images)
$('img.retina-large').retina({
    customFileNameCallback: function($this) {
        newImageSrc = $this.attr('data-retina') || $this.attr('src');
        if (!/Mobile/i.test(navigator.userAgent) ) {
            // Get filename sans extension
            var baseFileName = newImageSrc.replace(/.[^.]+$/,'');
            var baseFileExtension = newImageSrc.replace(/^.*\./,'');

            newImageSrc = baseFileName + '@2x.' + baseFileExtension; 
        }
        return newImageSrc;
    }
});

Another suggestion: make @2x the default suffix option, since that's the most common naming convention for retina images.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.