zoukankan      html  css  js  c++  java
  • JS,Jquery获取各种屏幕的宽度和高度

    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

    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

    })

    页面scroll到对应位置:

    这里要用到的知识点是:

    .offset().top 

    缓动效果:

    $('html, body').animate({
    scrollTop: value
    },400)

    $('html, body') 防止低版本IE无效;

    //step scroll
            $('.step_info').on('click','a',function(){
                $(this).addClass('active').siblings().removeClass('active');
                if($(this).hasClass('step_1')){
                    var s1Height = $('.cate_jump').offset().top - 130;
                    $('html, body').animate({
                        scrollTop:s1Height
                    },400)
                }else if($(this).hasClass('step_2')){
                    var s2Height = $('.w_notice').offset().top - 110;
                    $('html, body').animate({
                        scrollTop:s2Height
                    },400)
                }
            });

  • 相关阅读:
    DataGridView 鼠标双击获得行列索引
    浅谈MVC、MVP、MVVM架构模式的区别和联系
    Codeforces 336D Dima and Trap Graph 并查集
    Codeforces 601C Kleofáš and the n-thlon 概率dp
    Codeforces 311B Cats Transport 斜率优化dp
    Codeforces 908F New Year and Rainbow Roads
    Codeforces 12D Ball cdq分治
    Codeforces 291 E Tree-String Problem AC自动机
    Codeforces 932E Team Work 数学
    Codeforces 463E Caisa and Tree
  • 原文地址:https://www.cnblogs.com/3box/p/4929733.html
Copyright © 2011-2022 走看看