开发者

jQuery jPicker users: hexadecimal returns 8 digit value?

开发者 https://www.devze.com 2022-12-23 19:29 出处:网络
I\'ve just about got the jPicker script working flawlessly in my app. However, the value it returns contains 8 digits. Example: 212ebcff

I've just about got the jPicker script working flawlessly in my app. However, the value it returns contains 8 digits. Example: 212ebcff

Is there a preset variable that forces jPicker to return a 6 digit hex val开发者_如何学编程ue?


Unfortunately this was removed from jPicker itself, but it's getting added back next version: see here for details

For now you can just truncate the value with substring, the last ff is the alpha, like this:

val = val.substring(0,6);

or overall using get_Hex in the callback:

$('#Callbacks').jPicker(
  {},
  function(color) {
    alert('Color: #' + color.get_Hex());
  });
});


I also wanted to remove the alpha hex codes and I used a substring to do it. Here's how:

In the jpicker.js file (both full and minified) search for "get_Rgba:"
It's on line 531 in the full file (jpicker-1.0.13.js).

Use a substring on this line:

return r != null && g != null && b != null && a != null ? ColorMethods.rgbaToHex({ r: r, g: g, b: b, a: a }) : null;

So that it looks like this:

return r != null && g != null && b != null && a != null ? ColorMethods.rgbaToHex({ r: r, g: g, b: b, a: a }).substring(0, 6) : null;

It's working well for me. Hope this helps others!


This is Chris Tillman, the developer of the jPicker plugin. I have just published V1.1.0 of the picker which re-includes the alphaSupport variable. Default behavior is now for alphaSupport to be off unless turned on in the settings object. It also will use a 6-digit hex code instead of 8.

This update also includes a reworked internal event model, altering the color values from script (with full visual update), and a little better visual support for IE quirks mode in all versions. There are changes to the Color object that will require small changes in your interaction code, but it is very will documented at http://www.digitalmagicpro.com/jPicker/.

Check out the new code from Google code, just search for jPicker (can only post one link)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号