Giter Club home page Giter Club logo

adaptive-images's Introduction

Code Climate Test Coverage Issue Count Build Status

TalkTalk Adaptive Images

The purpose of this module is to replicate the functionality of the HTML5 tag until such a time that it is available in all browsers.

Installation

To install

bower install talktalplc/adaptive-images --save

You can then reference it within your application using app.adaptiveImage

Configuration

Whilst this module supports retina and non-retina images, it does not feature detect, however it has been built to work with your existing feature detection library (we use Modernizr Retina Test).

The example below will show you how to configure this module with the Modernizr Retina Test.

angular.module('myApp', [])
    .config(['adaptiveImageProvider', function(adaptiveImageProvider){
        adaptiveImageProvider.setHires( Modernizr.hires );
    }]);

By Default, it is configured to work with the TalkTalk breakpoints, these are:

  • xs: 0px -> 599px
  • sm: 600px -> 768px
  • md: 768px -> 1024px
  • lg: 1025px +

You can however easily configure it for your own breakpoints.

angular.module('myApp', [])
    .config(['adaptiveImageProvider', function(adaptiveImageProvider){
        adaptiveImageProvider.setBreakpoint('xs', 0);
        adaptiveImageProvider.setBreakpoint('sm', 768);
        adaptiveImageProvider.setBreakpoint('md', 992);
        adaptiveImageProvider.setBreakpoint('lg', 1200);
    }]);

If you've got any non-bootstrap 3 standard breakpoints, you can also set them in the config

angular.module('myApp', [])
    .config(['adaptiveImageProvider', function(adaptiveImageProvider){
        adaptiveImageProvider.setBreakpoint('xl', 2000);
    }]);

Use

For each breakpoint you wish an image to show at, simply add an adaptive-img-set. You can specify the difference between a non-retina and retina image by adding the hi-res attribute.

<adaptive-img alt="A responsive image">
    <adaptive-img-set breakpoint="xs" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=xs-1x&w=350&h=150"></adaptive-img-set>
    <adaptive-img-set breakpoint="sm" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=sm-1x&w=350&h=150"></adaptive-img-set>
    <adaptive-img-set breakpoint="md" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=md-1x&w=350&h=150"></adaptive-img-set>
    <adaptive-img-set breakpoint="lg" src="https://placeholdit.imgix.net/~text?txtsize=33&txt=lg-1x&w=350&h=150"></adaptive-img-set>
    <adaptive-img-set breakpoint="xs" hi-res src="https://placeholdit.imgix.net/~text?txtsize=33&txt=xs-2x&w=700&h=300"></adaptive-img-set>
    <adaptive-img-set breakpoint="sm" hi-res src="https://placeholdit.imgix.net/~text?txtsize=33&txt=sm-2x&w=700&h=300"></adaptive-img-set>
    <adaptive-img-set breakpoint="md" hi-res src="https://placeholdit.imgix.net/~text?txtsize=33&txt=md-2x&w=700&h=300"></adaptive-img-set>
    <adaptive-img-set breakpoint="lg" hi-res src="https://placeholdit.imgix.net/~text?txtsize=33&txt=lg-2x&w=700&h=300"></adaptive-img-set>
</adaptive-img>

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.