All Projects → karlhorky → Gray

karlhorky / Gray

Licence: mit
Make an image grayscale in all browsers

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Gray

Rangeslider.js
🎚 HTML5 input range slider element polyfill
Stars: ✭ 2,153 (+279.05%)
Mutual labels:  polyfill, jquery
Jquery Contextmenu
jQuery contextMenu plugin & polyfill
Stars: ✭ 2,148 (+278.17%)
Mutual labels:  polyfill, jquery
Sugar
A Javascript library for working with native objects.
Stars: ✭ 4,457 (+684.68%)
Mutual labels:  polyfill
Resize Observer
Polyfills the ResizeObserver API.
Stars: ✭ 540 (-4.93%)
Mutual labels:  polyfill
Jquery Cropper
A jQuery plugin wrapper for Cropper.js.
Stars: ✭ 516 (-9.15%)
Mutual labels:  jquery
Jquery.thailand.js
ตัวช่วยกรอกที่อยู่ที่ดีที่สุดในไทย ไม่ต้องใช้ Server Side!
Stars: ✭ 490 (-13.73%)
Mutual labels:  jquery
Jquery.sumoselect
A jQuery Single/Multi Select plugin which can be used on almost any device
Stars: ✭ 527 (-7.22%)
Mutual labels:  jquery
Instagram Clone
An Instagram-clone with my own flavors and features. Own the project with 5 simple steps!! 📸💝☢️
Stars: ✭ 479 (-15.67%)
Mutual labels:  jquery
Headless Chrome Crawler
Distributed crawler powered by Headless Chrome
Stars: ✭ 5,129 (+802.99%)
Mutual labels:  jquery
Intercooler Js
Making AJAX as easy as anchor tags
Stars: ✭ 4,662 (+720.77%)
Mutual labels:  jquery
Force Js
The easy way to scroll and animate your page
Stars: ✭ 536 (-5.63%)
Mutual labels:  jquery
Fe Interview Questions
目前最全的前端开发面试题及答案
Stars: ✭ 502 (-11.62%)
Mutual labels:  jquery
Html5
HTML5学习、总结、实践
Stars: ✭ 493 (-13.2%)
Mutual labels:  jquery
Responsive Tabs
Responsive Tabs is a jQuery plugin that provides responsive tab functionality. The tabs transform to an accordion when it reaches a CSS breakpoint. You can use this plugin as a solution for displaying tabs elegantly on desktop, tablet and mobile.
Stars: ✭ 529 (-6.87%)
Mutual labels:  jquery
Domjudge
DOMjudge programming contest jury system
Stars: ✭ 484 (-14.79%)
Mutual labels:  jquery
Cheerio
Fast, flexible, and lean implementation of core jQuery designed specifically for the server.
Stars: ✭ 24,616 (+4233.8%)
Mutual labels:  jquery
Jtsage Datebox
A multi-mode date and time picker for Bootstrap (3&4), jQueryMobile, Foundation, Bulma, FomanticUI, and UIKit (or others)
Stars: ✭ 481 (-15.32%)
Mutual labels:  jquery
Undom
🍩 1kb minimally viable DOM Document implementation
Stars: ✭ 496 (-12.68%)
Mutual labels:  polyfill
Ajax Datatables Rails
A wrapper around DataTable's ajax methods that allow synchronization with server-side pagination in a Rails app
Stars: ✭ 520 (-8.45%)
Mutual labels:  jquery
Webassemblyjs
Toolchain for WebAssembly
Stars: ✭ 566 (-0.35%)
Mutual labels:  polyfill

gray

CSS Styles and jQuery plugin to display images in grayscale.npm version

Demo

Support:

  • IE 6-11 (10 and 11 use the JavaScript polyfill)
  • Edge 12+ (12 uses the JavaScript polyfill)
  • 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 npm:

npm install --save jquery-gray

Or Bower:

bower install --save gray

Or use the CDN links:

https://npmcdn.com/[email protected]/css/gray.min.css
https://npmcdn.com/[email protected]/js/jquery.gray.min.js

Or you can just download it.

How to Use

  1. Add the CSS from gray.css.

    If you want to use your own CSS selector instead of .grayscale, edit or copy the 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();
    

    The effect can be toggled with the grayscale-off class:

    $('.grayscale').toggleClass('grayscale-off');
    
  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.jpg);
      background-size    : auto 72px;
      background-position: -180px 0;
      display            : inline-block;
      width              : 180px;
      height             : 72px;
    "
      class="grayscale"
    ></div>
    

    Non-numeric background-size (cover, contain, ...) and background-position (center, ...) are not currently supported (pull requests welcome!).

  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. If you are using Modernizr already, make sure that the required feature detects are included in your build.

  6. Revel in your absolute and utter awesomeness.

Caveats

Non-numeric background-size and background-position

Non-numeric background-size (cover, contain, ...) and background-position (center, ...) are not currently supported.

Percentage-based background-position

Percentage-based background-position (ex. 50% 50%, ...) is not currently supported.

Non-visible elements will not be correctly initialized

Calling the plugin on hidden images (or other images that cannot have their size calculated) will fail in polyfill browsers. Workarounds can be found in the discussions at #57 and #40.

Child elements removed in browsers without support for CSS filters

Target elements with child elements will have those child elements removed in browsers without support for CSS filters. #61

Event listeners removed in browsers without support for CSS filters

Target elements with event listeners removed in browsers without support for CSS filters. #65

Colored borders

Colored borders will be also converted to grayscale in non-polyfill browsers. To also convert to grayscale in polyfill browsers, the class grayscale-replaced can be used:

.grayscale-replaced {
  border-color: #494949 !important;
}

How it Works

In browsers that support css filters, the styles in gray.css will use CSS filters to turn the image gray.

Modernizr

The jquery.gray plugin uses the Modernizr._prefixes, css-filters, Inline SVG and svg-filters feature detects from Modernizr to determine browser support. If a browser supports inline SVG and SVG filters but not CSS filters, the plugin replaces the elements with SVG elements with filters.

Changelog

  • v1.7.0: Upgrade Modernizr #80
  • v1.6.0: Throw error when modernizr feature detects not in build #71 #72
  • v1.5.0: Add SVG <title> to polyfill for accessibility (demo)
  • v1.4.5: Fix sizing of img tags with padding
  • v1.4.4: Fix bug with missing padding properties with background images
  • v1.4.3: Fix bug with padding on img tag
  • v1.4.2: Add Firefox 35+ support, normalize cross-browser rendering
  • v1.4.1: Fix bug with display: none on parents
  • v1.4.0: Add support for programmatic toggling of grayscale
  • v1.3.6: Fix image size with resized img tag and grayscale-fade in polyfill
  • v1.3.5: Declare variables to fix error in strict mode
  • v1.3.4: Don't override existing modernizr
  • v1.3.3: Update minified js to match source
  • 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

License

MIT © Karl Horky

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].