Giter Site home page Giter Site logo

gray's Introduction

gray

Make an image gray in all browsers. Demo.

Support:

  • IE 6-9
  • IE 10-11 (inline SVG via JavaScript)
  • Firefox 10+, Firefox on Android
  • Chrome 19+, Chrome for Android 25+
  • Android Browser 4.4+
  • Safari 6+, Safari iOS 6+
  • Opera 15+, Opera Mobile 16+
  • BlackBerry Browser 10+

Installation

You can install with Bower:

bower install --save gray

Or use the CDN links:

//cdn.jsdelivr.net/jquery.gray/1.3.2/gray.min.css
//cdn.jsdelivr.net/jquery.gray/1.3.2/jquery.gray.min.js

Or you can just download it.

How to Use

  1. Add the CSS from gray.css.

  2. Add the plugin after jQuery at the bottom of the body.

    <script src="/js/jquery.gray.min.js"></script>

    The plugin automatically initializes for all elements with a class of grayscale. The plugin can also be called manually with:

    $('.my-grayscale-class').gray();
  3. Add your image with a class of grayscale.

    <img src="/img/color.jpg" class="grayscale">

    Images with CSS background-image, background-size and (numeric) background-position are also supported:

    <div style="
      background-image   : url(/img/color-sprite-lg.png);
      background-size    : auto 72px;
      background-position: -180px 0;
      display            : inline-block;
      width              : 180px;
      height             : 72px;
    " class="grayscale"></div>
  4. (Optional) Add class of grayscale-fade if you want transitioning from grayscale back to color on hover

    <img src="/img/color.jpg" class="grayscale grayscale-fade">
  5. Revel in your absolute and utter awesomeness.

Changelog

  • v1.3.2: remove grayscale on hover in ie6-9 (fade option), use same svg filter in polyfill as in css
  • v1.3.1: bugfix for empty gray class name
  • v1.3.0: rename fade class to grayscale-fade to resolve conflict with bootstrap
  • v1.2.0: IE shim: Copy styles from element to replacement element
  • v1.1.1: Improve documentation and demo
  • v1.1.0: Support for background images with basic background-size and background-position
  • v1.0.0: First basic version with support for <img> tags

TODO

  • background-size: cover, background-size: contain
  • feature detection for SVG filters instead of client detection
  • better JavaScript templating for SVG

License

MIT © kununu

gray's People

Contributors

karlhorky avatar splagemann avatar

Watchers

Jayden Spring 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.