Giter Club home page Giter Club logo

retina.js's Introduction

retina.js

Script to convert images for "retina" displays

How it works

When a page is loaded retina.js checks media queries (madrobby's media queries) to see if the display the page is being rendered on is 'retina' (meaning high pixel density). If it's a retina quality display, it replaces all html images with a new image path that has '2x' appended to the filename. This means that you need to create 2x versions of images and place them alongside your 1x images with 2x appended to the filename. The script uses a symbol separator to help keep the filename namespace clear. By default '@' is the namespace separator, which follows convention elsewhere. However, in some cases the '@' symbol will be an invalid filename character (for instance, on AppEngine).

This is a little bit more of a manual approach than something like imulus's retina.js which actually automatically checks for the existence of image files with '@2x' appended to the end of the filename and replaces them if they exist. With this version, you have to add a class to the image in order for the script to attempt replacement. In lots of use cases you may be updating existing sites and may not have 2x images of existing graphics. This more manual approach saves the processing and requests that are required to automatically check all images.

Usage

Include retina.js in the footer of your site. If you'd like to use a different separator than the '@' symbol, somewhere before you load retina.js, declare a variable named 'retinaImageSeperator' and assign it a string of the separator you'd like to use:

retinaImageSeperator = '--';

For all images that you'd like replaced, add a class named 'hi-res'. Images without this class won't be replaced.

So...

<img class='hi-res' src='avatar.png' />

... will be replaced with:

<img class='hi-res' src='[email protected]' />

retina.js's People

Contributors

kevinchampion avatar

Watchers

James Cloos avatar  avatar

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.