Показать сообщение отдельно
  #1 (permalink)  
Старый 31.08.2009, 10:57
Аватар для JSprog
L
Отправить личное сообщение для JSprog Посмотреть профиль Найти все сообщения от JSprog
 
Регистрация: 16.08.2009
Сообщений: 416

Модуль для работы с геометрией окна
Хочу представить вам ещё один модуль Дэвида Флэнагана.
Для работы с геометрией окна.
Задача модуля:представить кросс-браузерные методы для определения:
1)положения окна на экране
2)размеров клиентской области окна
3)размеров документа
4)смещения документа относительно окна
var Geometry = {};
if (window.screenLeft === undefined) { // Для IE и других
Geometry.getWindowX = function() { return window.screenLeft; };
Geometry.getWindowY = function() { return window.screenTop; };
}
else if (window.screenX) { // Для Firefox и других
Geometry.getWindowX = function() { return window.screenX; };
Geometry.getWindowY = function() { return window.screenY; };
}


if (window.innerWidth) { // Все броузеры, кроме IE
Geometry.getViewportWidth = function() { return window.innerWidth; };
Geometry.getViewportHeight = function() { return window.innerHeight; };
Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
Geometry.getVerticalScroll = function() { return window.pageYOffset; };
}
else if (document.documentElement && document.documentElement.clientWidth) {
// Эти функции предназначены для IE и документов с объявлением DOCTYPE
Geometry.getViewportWidth =
function() { return document.documentElement.clientWidth; };
Geometry.getViewportHeight =
function() { return document.documentElement.clientHeight; };
Geometry.getHorizontalScroll =
function() { return document.documentElement.scrollLeft; };
Geometry.getVerticalScroll =
function() { return document.documentElement.scrollTop; };
}
else if (document.body.clientWidth) {
// Эти функции предназначены для IE без объявления DOCTYPE
Geometry.getViewportWidth =
function() { return document.body.clientWidth; };
Geometry.getViewportHeight =
function() { return document.body.clientHeight; };
Geometry.getHorizontalScroll =
function() { return document.body.scrollLeft; };
Geometry.getVerticalScroll =
function() { return document.body.scrollTop; };
}


// Следующие функции возвращают размеры документа.
// Они не имеют отношения к окну, но бывает удобно иметь их.
if (document.documentElement && document.documentElement.scrollWidth) {
Geometry.getDocumentWidth =
function() { return document.documentElement.scrollWidth; };
Geometry.getDocumentHeight =
function() { return document.documentElement.scrollHeight; };
}
else if (document.body.scrollWidth) {
Geometry.getDocumentWidth =
function() { return document.body.scrollWidth; };
Geometry.getDocumentHeight =
function() { return document.body.scrollHeight; };
}
__________________
Лови позитив

Последний раз редактировалось JSprog, 31.08.2009 в 12:32.
Ответить с цитированием