GithubHelp home page GithubHelp logo

yansenlei / jquery-dropper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sstrudeau/jquery-dropper

0.0 1.0 0.0 526 KB

jquery "eye dropper" color picker plugin

Home Page: http://sstrudeau.com/jquery-dropper/demo/index.html

HTML 21.58% JavaScript 78.42%

jquery-dropper's Introduction

dropper: a jQuery plugin

This jQuery plugin uses the HTML5 canvas element to create an "eyedropper"-style color picker for any image.

Limitations

Internet Explorer Not Supported

Internet Explorer does not support the HTML5 canvas element natively. The popular VML hack for simulating canvas in IE will not work. VML does not give pixel-level access to images. See this thread

Images must be in same domain as the web page

In order to get pixel-level access to the image, the image must be hosted on the same domain as the web page. See the canvas security section of the HTML5 spec

TODO: Test redirect proxy as a possible workaround

Usage

Load jquery & the plug-in: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script src="jquery.dropper.js" type="text/javascript"></script>

Select the image or set of images you'd like to be enabled with a dropper: <script type="text/javascript" charset="utf-8"> jQuery(document).ready(function() { jQuery('img.dropper').dropper(); }); </script>

This will replace all img elements with a 'class' of 'dropper' with a canvas element and dropper-style color picker.

Callbacks

The plugin offers three callback methods that can be passed to the .dropper() method:

  • clickCallback
  • mouseMoveCallback
  • mouseOutCallback

Each callback is called with a single argument, a color object. The color object has has 5 attributes: r, g, b and alpha which are 0-255 integers for the "red", "green", "blue" and "alpha transparency" channel of the image. And "rgbhex" which is the 6 character hexadecimal representation of the color.

Example:

<script type="text/javascript" charset="utf-8">
	jQuery(document).ready(function() {
		jQuery('img.dropper').dropper({
			clickCallback: function(color) {
				alert("You clicked on color: #"+ color.rgbhex);
			};
		});
	});			
</script>

See the included "demo" folder for a simple, more practical example.

TODO: pass more args back to callbacks; investigate callback naming conventions, event propagation

Author

Scott Trudeau (@sstrudeau) for Apartment Therapy

See Also

Favonius' fork: dropperredux

Demo Image Credits

The demo uses three image from Flickr. Each is licensed as Creative Commons, Attribution-Share Alike 2.0

License

Dual licensed under the MIT License and the GPL license

Copyright (c) 2010, Scott Trudeau ([email protected])

jquery-dropper's People

Contributors

sstrudeau avatar

Watchers

 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.