How does jquery imitate the ps color pickup function
This article introduces the relevant knowledge of "how jquery imitates the color pickup function of ps". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Effect display
2.html code: index.html
Title
3. Plug-in code:
(function ($) {$.fn.pickerColor=function (option) {var opt= {ck:function () {}}, _ this=this opt=$.extend (opt,option); _ this.on ('click',function (e) {var canvasObj ='; $('body') .append (canvasObj); var cvs = document.getElementById ("canvasPickerColor"), ctx = cvs.getContext (' 2d') cvs.height=1;cvs.width=1 var img = new Image () Img.src=_this.attr ('src'); var osX=e.offsetX,osY=e.offsetY ctx.drawImage (img,osX,osY,1,1,0,0,1,1); var imgData=ctx.getImageData; console.log (imgData) if (opt.ck) opt.ck (imgData.data [0] +','+ imgData.data [1] +','+ imgData.data [2]);})}) (jQuery)
3, plug-in call
$(function () {$('.source'). PickerColor ({ck:function (data) {console.log (data) $('.color'). Css ('background','rgba (' + data+',1)')})) this is the end of the introduction of "how jquery imitates the color pickup function of ps". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!