Miałem problem z planowaniem z nagłówkami wierszy (godziny) i nagłówkami kolumn (dni). Chciałem zachować widoczność obu. Aplikacja pokazuje zawartość w ramce IFrame, więc utworzyłem poziomy DIV i pionowy DIV poza ramką IFrame ze stylem "przepełnienie: ukryty". Następnie zsynchronizowałem przewijanie z zdarzeniem "onscroll" ramki IFrame.
Oto mój kod synchronizować nagłówki z przewijaniem:
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);
}
}
Moje rozwiązanie nie jest takie proste, bo trzeba było ustawić w „onresize” szerokość poziomej DIV i wysokość pionową DIV. To powoduje większą złożoność, ponieważ funkcja onResize może być uruchamiana wiele razy na sekundę, a zdarzenie to jest nawet uruchamiane w IE8, gdy występuje przewijanie. Więc zrobiłem setTimeout aby zapobiec nagłówki być odświeżana zbyt często:
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); }
}
I wreszcie metoda makeHeaders()
trzeba zmienić rozmiar DIV:
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);
} }
Może to być możliwe, aby nie używać IFRAME i używać tylko 3 DIVS: po jednym dla każdego nagłówka, a ostatni dla treści. Ale mechanizm musi być taki sam, jak myślę: potrzebuje synchronizacji pomiędzy pozycjami przewijania.
poważaniem,
Możliwy duplikat: http://stackoverflow.com/q/983031/214773 –
@ JúlioSantos: Nie, ** ** to pytanie nie wspomina jQuery (lub nawet JavaScript) na wszystkich . –
Och, OK, punkt wzięty. Dodam odpowiedź. –