zent
Version:
一套前端设计语言和基于React的实现
53 lines (52 loc) • 1.51 kB
JavaScript
export function calculateChange(e, skip, props, container) {
!skip && e.preventDefault();
var containerWidth = container.clientWidth;
var containerHeight = container.clientHeight;
var x = typeof e.pageX === 'number' ? e.pageX : e.touches[0].pageX;
var y = typeof e.pageY === 'number' ? e.pageY : e.touches[0].pageY;
var left = x - (container.getBoundingClientRect().left + window.pageXOffset);
var top = y - (container.getBoundingClientRect().top + window.pageYOffset);
if (props.direction === 'vertical') {
var a = void 0;
if (top < 0) {
a = 0;
}
else if (top > containerHeight) {
a = 1;
}
else {
a = Math.round((top * 100) / containerHeight) / 100;
}
if (props.hsl.a !== a) {
return {
h: props.hsl.h,
s: props.hsl.s,
l: props.hsl.l,
a: a,
source: 'rgb',
};
}
}
else {
var a = void 0;
if (left < 0) {
a = 0;
}
else if (left > containerWidth) {
a = 1;
}
else {
a = Math.round((left * 100) / containerWidth) / 100;
}
if (props.a !== a) {
return {
h: props.hsl.h,
s: props.hsl.s,
l: props.hsl.l,
a: a,
source: 'rgb',
};
}
}
return null;
}