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)
                }
            });

  • 相关阅读:
    关于html5的一些知识。
    常见的http状态码总结。
    踩坑记录-安装node-sass运行报错TypeError: this.getResolve is not a function at Object.loader
    踩坑记录-!!vue-style-loader!css-loader错误
    koa-passport做登录注册验证
    nuxt项目里使用vuex状态树
    node(koa、nuxt等项目)中使用import报错问题
    koa+nodemailer实现邮箱验证注册功能
    踩坑记录-nuxt引入vuex报错store/index.js should export a method that returns a Vuex instance.
    常用shell命令积累
  • 原文地址:https://www.cnblogs.com/3box/p/4929733.html
Copyright © 2011-2022 走看看