Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply an additional offset #263

Open
webchaz opened this issue Nov 7, 2014 · 1 comment
Open

Apply an additional offset #263

webchaz opened this issue Nov 7, 2014 · 1 comment

Comments

@webchaz
Copy link

webchaz commented Nov 7, 2014

Is there anyway to update the left and top values when showing the color picker? So that it can be say a few pixels less to the left, etc.

Thanks!

@bgrins
Copy link
Owner

bgrins commented Nov 10, 2014

Right now the offset is gotten here:

spectrum/spectrum.js

Lines 948 to 969 in 112a665

function getOffset(picker, input) {
var extraY = 0;
var dpWidth = picker.outerWidth();
var dpHeight = picker.outerHeight();
var inputHeight = input.outerHeight();
var doc = picker[0].ownerDocument;
var docElem = doc.documentElement;
var viewWidth = docElem.clientWidth + $(doc).scrollLeft();
var viewHeight = docElem.clientHeight + $(doc).scrollTop();
var offset = input.offset();
offset.top += inputHeight;
offset.left -=
Math.min(offset.left, (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ?
Math.abs(offset.left + dpWidth - viewWidth) : 0);
offset.top -=
Math.min(offset.top, ((offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ?
Math.abs(dpHeight + inputHeight - extraY) : extraY));
return offset;
}
, and is not changeable.

But I think that you could bind to the reflow event and tweak the values offset on el.spectrum("container"). I'd guess something like this might work (untested):

var el = $("element").spectrum();
el.on("reflow.spectrum", function() {
    var container = el.spectrum("container");
    var offset = container.offset();
    offset.left -= 5;
    container.offset(offset);
});

Does this work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants