que tenían el problema de la planificación con los encabezados de fila (horas) y títulos de las columnas (días). Quería mantener visibles los dos. La aplicación muestra el contenido en un iframe, por lo que he creado un DIV horizontal y vertical de un DIV fuera del marco flotante con un estilo "overflow: hidden". Luego he sincronizado las permutas con el evento "onscroll" del IFrame.
Aquí está mi código para sincronizar los encabezados con desplazamiento:
window.onscroll = function() {
try {
// - Scroll days header (on the top) horizontally
var offsetX = (document.documentElement && document.documentElement.scrollLeft) || document.body.scrollLeft; // Source: http://stackoverflow.com/questions/2717252/document-body-scrolltop-is-always-0-in-ie-even-when-scrolling
var header1Div = window.parent.document.getElementById("EntetesColonnes");
header1Div.scrollLeft = offsetX;
// - Scroll hours header (on the left) vertically
var offsetY = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop; // Source: http://stackoverflow.com/questions/2717252/document-body-scrolltop-is-always-0-in-ie-even-when-scrolling
var header2Div = window.parent.document.getElementById("HeaderHoursLeft");
header2Div.scrollTop = offsetY;
}
catch (ex) {
alert("FrmPlanningChirurgien/window.onscroll: " + ex.message);
}
}
Mi solución no es tan simple, porque tenía que poner en "onResize" el ancho de DIV horizontal y la altura del DIV vertical. Entonces esto induce una mayor complejidad, ya que onResize se puede disparar muchas veces por segundo, y este evento incluso se dispara en IE8 cuando se produce el desplazamiento. así que he hecho un setTimeout para evitar que las tuberías principales a ser redibujado con demasiada frecuencia:
var PREVIOUS_frameWidth = 0;
var PREVIOUS_frameHeight = 0;
var timerMakeHeaders = null;
window.onresize = function() {
try {
var frameWidth = CROSS.getWindowWidth();
var frameHeight = CROSS.getWindowHeight();
if (frameWidth != PREVIOUS_frameWidth || frameHeight != PREVIOUS_frameHeight) {
// - *** Launch headers creation method
// - If there is another query to redraw, the Timer is stopped and recreated.
// - The headers are only redrawn when Timer fires.
if (timerMakeHeaders != null) {
window.clearTimeout(timerMakeHeaders);
timerMakeHeaders = null;
}
timerMakeHeaders = window.setTimeout(makeHeaders, 50);
// - *** Store new values
PREVIOUS_frameWidth = frameWidth;
PREVIOUS_frameHeight = frameHeight;
}
} catch (e) { alert("Erreur window.onresize/FrmPlanningChirurgien.aspx : " + e.message); }
}
Y, finalmente, el método makeHeaders()
tener que cambiar el tamaño de DIVs:
function makeHeaders() {
// (...)
var frame = window.parent.document.getElementById("CalendarFrame");
var iframeRect = frame.getBoundingClientRect();
headerDiv.style.width = iframeRect.right - iframeRect.left - 20; // The 20 pixels are here for the vertical scrollbar width
headerDiv.scrollLeft = frame.scrollLeft;
// (...)
var headerHourDiv = window.parent.document.getElementById("HeaderHoursLeft");
var newHeight = iframeRect.bottom - iframeRect.top - 20 - 7; // The VISIBLE width for the DIV must be equal to IFRAME Width minus the scroll width or height
headerHourDiv.style.height = newHeight;
headerHourDiv.scrollTop = frame.scrollTop;
}
catch (e) {
alert("makeHeaders: " + e.message);
} }
Tal vez podría ser posible no utilizar un IFRAME, y usar solo 3 DIVS: uno para cada encabezado y el último para el contenido. Pero el mecanismo tiene que ser el mismo, creo: necesita una sincronización entre las posiciones de desplazamiento.
Saludos,
Posible duplicado: http://stackoverflow.com/q/983031/214773 –
@ JúlioSantos: No, ** ** esta cuestión no menciona jQuery (o incluso JavaScript) en todo . –
Oh, OK, punto tomado. Añadiré una respuesta. –