jQuery 獲取屏幕高度、寬度的簡單實(shí)現(xiàn)案例
做手機(jī)Web開發(fā)做瀏覽器兼容用到了,所以在網(wǎng)上找了些匯總下。
alert($(window).height()); //瀏覽器當(dāng)前窗口可視區(qū)域高度
alert($(document).height()); //瀏覽器當(dāng)前窗口文檔的高度
alert($(document.body).height());//瀏覽器當(dāng)前窗口文檔body的高度
alert($(document.body).outerHeight(true));//瀏覽器當(dāng)前窗口文檔body的總高度 包括border padding margin
alert($(window).width()); //瀏覽器當(dāng)前窗口可視區(qū)域?qū)挾?
alert($(document).width());//瀏覽器當(dāng)前窗口文檔對象寬度
alert($(document.body).width());//瀏覽器當(dāng)前窗口文檔body的高度
alert($(document.body).outerWidth(true));//瀏覽器當(dāng)前窗口文檔body的總寬度 包括border padding margin
// 獲取頁面的高度、寬度
function getPageSize() {
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = window.innerWidth + window.scrollMaxX;
yScroll = window.innerHeight + window.scrollMaxY;
} else {
if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
}
var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
if (document.documentElement.clientWidth) {
windowWidth = document.documentElement.clientWidth;
} else {
windowWidth = self.innerWidth;
}
windowHeight = self.innerHeight;
} else {
if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else {
if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
}
}
// for small pages with total height less then height of the viewport
if (yScroll < windowHeight) {
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
// for small pages with total width less then width of the viewport
if (xScroll < windowWidth) {
pageWidth = xScroll;
} else {
pageWidth = windowWidth;
}
arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
return arrayPageSize;
}
// 滾動(dòng)條
document.body.scrollTop;
$(document).scrollTop();
以上這篇jQuery 獲取屏幕高度、寬度的簡單實(shí)現(xiàn)案例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- JS和jquery獲取各種屏幕的寬度和高度的代碼
- JQuery獲取當(dāng)前屏幕的高度寬度的實(shí)現(xiàn)代碼
- jQuery javascript獲得網(wǎng)頁的高度與寬度的實(shí)現(xiàn)代碼
- jQuery獲取頁面及個(gè)元素高度、寬度的總結(jié)——超實(shí)用
- jquery實(shí)現(xiàn)動(dòng)態(tài)改變div寬度和高度
- jQuery獲得document和window對象寬度和高度的方法
- jQuery設(shè)置指定網(wǎng)頁元素寬度和高度的方法
- jquery動(dòng)態(tài)改變div寬度和高度
- js和jquery如何獲取圖片真實(shí)的寬度和高度
- javascript原生和jquery庫實(shí)現(xiàn)iframe自適應(yīng)高度和寬度
- jquery實(shí)現(xiàn)在頁面加載完畢后獲取圖片高度或?qū)挾?/a>
- JQuery獲取各種寬度、高度(format函數(shù))實(shí)例
- js/jquery獲取瀏覽器窗口可視區(qū)域高度和寬度以及滾動(dòng)條高度實(shí)現(xiàn)代碼
- jquery 得到當(dāng)前頁面高度和寬度的兩個(gè)函數(shù)
相關(guān)文章
jQuery AnythingSlider滑動(dòng)效果插件
2009年最受歡迎jQuery插件—AnythingSlider【滑動(dòng)】2010-02-02
jQuery時(shí)間日期三級聯(lián)動(dòng)(推薦)
這篇文章主要介紹了jQuery時(shí)間日期三級聯(lián)動(dòng)的實(shí)現(xiàn)代碼,代碼簡答易懂,非常實(shí)用,需要的朋友參考下吧2016-11-11
jQuery的實(shí)現(xiàn)原理的模擬代碼 -5 Ajax
對于 xhr 對象來說,我們主要通過異步方式訪問服務(wù)器,在 onreadystatechange 事件中處理服務(wù)器回應(yīng)的內(nèi)容。簡單的 xhr 使用如下所示。2010-08-08
jQuery 自動(dòng)增長的文本輸入框?qū)崿F(xiàn)代碼
文本輸入框內(nèi)的字?jǐn)?shù)不能確定,而input type="text"的size是固定的,當(dāng)字?jǐn)?shù)超過size時(shí)(默認(rèn)是20),先輸入的內(nèi)容就會從文本框的左端隱藏起來,不便于輸入。2010-04-04
jQuery+ajax實(shí)現(xiàn)鼠標(biāo)單擊修改內(nèi)容的思路
這篇文章主要介紹了jQuery+ajax實(shí)現(xiàn)鼠標(biāo)單擊修改內(nèi)容的思路及核心代碼,需要的朋友可以參考下2014-06-06
jquery之a(chǎn)jaxfileupload異步上傳插件(附工程代碼)
在處理文件上傳時(shí)需要使用到文件的異步上傳,這里使用Jquery Ajax File Uploader這個(gè)組件,服務(wù)器端采用struts2來處理文件上傳2013-04-04

