Bob Ippolito wrote:
[...]
Anyway, the problem with
setting positions is the whole style.display.position issue, what's the
best way to handle that? Clearly it has to be changed for elements
whose positions are static, but what to do with fixed/ relative? Should
it all be forced to absolute, or what?
I'd prefer to force as little as posible.
Relative doesn't need to be changed as long as you modify the style.left
and style.top to the correct value to get the element to the specified
document position:
var left = parseInt(computedStyle(element, 'left'), 10);
var top = parseInt(computedStyle(element, 'top'), 10);
if (isNaN(currentLeft) || isNaN(currentTop)) {
//Fallback to set absolute position?
}
var elementPos = elementPosition(element);
left += (absolutePos.x - elementPos.x);
top += (absolutePos.y - elementPos.y);
updateNodeAttributes(element, {'style': {'left': left + 'px',
'top': top + 'px'} });
I didn't test the snippet, but that's the idea. And it should check if
the value returned by computedStyle is measured in 'px' or not.
With respect to fixed position, maybe you can play with the scroll
offset and that sort of things, but I can't imagine why I would need to
give absolute coordinates to a fixed element, and still keep the fixed
positioning. YAGNI?
Greetings,
--
Leonardo Soto