Home  >  Article  >  Web Front-end  >  How to find the height of the screen in jquery

How to find the height of the screen in jquery

藏色散人
藏色散人Original
2023-02-07 10:40:423494browse

Jquery method to find the screen height: 1. Get the height of the visible area of ​​the browser's current window through the "alert($(window).height());" method; 2. Through "alert($(document ).height());" method to obtain the height of the browser's current window document; 3. Obtain the height of the browser's current window document body through the "alert($(document.body).height());" method.

How to find the height of the screen in jquery

The operating environment of this tutorial: Windows 10 system, jquery version 3.2.1, DELL G3 computer

How to find the height of the screen with jquery?

js or jQuery to get the various heights of the current screen

1. Reference address:

js or jQuery to get the various heights of the current screen Kind of height

jquery monitors the size change of the browsing window and executes the corresponding code

2.

1. Javascript:

网页可见区域宽: document.body.clientWidth
网页可见区域高: document.body.clientHeight
网页可见区域宽: document.body.offsetWidth (包括边线的宽)
网页可见区域高: document.body.offsetHeight (包括边线的高)
网页正文全文宽: document.body.scrollWidth
网页正文全文高: document.body.scrollHeight
网页被卷去的高: document.body.scrollTop
网页被卷去的左: document.body.scrollLeft
网页正文部分上: window.screenTop
网页正文部分左: window.screenLeft
屏幕分辨率的高: window.screen.height
屏幕分辨率的宽: window.screen.width
屏幕可用工作区高度: window.screen.availHeight
屏幕可用工作区宽度: window.screen.availWidth

2 , JQuery:

$(document).ready(function(){
alert($(window).height()); //浏览器当前窗口可视区域高度
alert($(document).height()); //浏览器当前窗口文档的高度
alert($(document.body).height());//浏览器当前窗口文档body的高度
alert($(document.body).outerHeight(true));//浏览器当前窗口文档body的总高度 包括border padding margin
alert($(window).width()); //浏览器当前窗口可视区域宽度
alert($(document).width());//浏览器当前窗口文档对象宽度
alert($(document.body).width());//浏览器当前窗口文档body的宽度
alert($(document.body).outerWidth(true));//浏览器当前窗口文档body的总宽度 包括border padding margin
})

3. When the window size changes

$(window).resize(function(){
   //执行代码块
});

4. Click to return to the top

$('.go_top').click(function(){
    if ($(window).scrollTop() > 0) {
    $("html,body").stop().animate({ scrollTop: 0 }, 200);
}
});
$(window).scroll(function(){
    var w_h = $(document).scrollTop();
    if(w_h>300){
        $('.go_top').fadeIn();
    }
    if(w_h<=300){
        $('.go_top').fadeOut();
    }
});

Recommended learning: "jQuery Video Tutorial"

The above is the detailed content of How to find the height of the screen in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn