zoukankan      html  css  js  c++  java
  • 自己封装的滚动条滚到底部和可视区域的插件

    (function(window,undefined){
        var jsSrollArra=function(){};
        /*计算高度轴的宽度*/
        jjsSrollArra.prototype={
            getScrollBar:function(){
                var el=document.createElement("p"),
                styles={
                    "100px",
                    height:"100px",
                    overflowY:"scroll"
                },i,scrollBarWidth;
                for(i in styles){
                    el.style[i]=styles[i];
                };
                document.body.appendChild(el);
                var scrollBarWidth=el.offsetWidth-el.clientWidth;
                document.body.removeChild(el);
                return scrollBarWidth;
            },
            /*计算可视区域*/
            /*调用方法
                jsSrollArra.visibleArea({
                    fatherId:fatherId//设置ID为在某个DIV的可视区域,设置为空或者不设置为在浏览器的可视区域
                    divId:id,//需要在可视区域DIV的id
                    visibleFunction:visibleFunction//在可视区域中执行的函数
                });
            **/
            visibleArea:function(params){
                var pot=params;
                if(pot.fatherId == "" || pot.fatherId == undefined){
                    var clients=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;
                }else{
                    var clients=document.getElementById(pot.fatherId).clientHeight;
                };
                if(typeof pot.divId == 'object'){
                    var divTop=pot.divId.getBoundingClientRect().top;
                }else{
                    var divTop=document.getElementById(pot.divId).getBoundingClientRect().top;
                };
                if(divTop<clients){
                    pot.visibleFunction();
                }
           },
            /*判断滚动条到底部或者顶部*/
            /*调用方法
                jsSrollArra.scrollHeight({
                    divId:id,//设置id为某个Div滚动到底部,不设置或者为空为浏览器滚动条
                    scrollTopFunction:scrollTopFunction//滚动到顶部执行的函数
                    scrollBottomFunction:scrollBottomFunction//滚动到底部执行的函数
                });
            **/
            scrollHeight:function(params){
                var pot=params;
                if(pot.divId == "" || pot.divId == undefined){
                    var clients=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;
                    var scrollTop=document.body.scrollTop;
                    var wholeHeight=document.body.scrollHeight;
                }else{
                    var clients=document.getElementById(pot.divId).clientHeight;
                    var scrollTop=document.getElementById(pot.divId).scrollTop;
                    var wholeHeight=document.getElementById(pot.divId).scrollHeight;
                };
                if(clients+scrollTop>=wholeHeight){
                    pot.scrollBottomFunction();
                }else if(scrollTop==0){
                    pot.scrollTopFunction();
                }
            }
        }
        window.jsSrollArra=jsSrollArra;
    })(window,undefined);
    var jsSrollArra= new jsSrollArra();
  • 相关阅读:
    【JZOJ 4274】【NOIP2015模拟10.28B组】终章-剑之魂
    【JZOJ 4281】【NOIP2015模拟10.29A组】三色树
    【Luogu P2824】[HEOI2016/TJOI2016]排序
    【Luogu P5490】【模板】扫描线
    【Luogu P2502】[HAOI2006]旅行
    【Luogu P1629】 邮递员送信
    【Luogu P4047】[JSOI2010]部落划分
    【Luogu P4071】[SDOI2016]排列计数
    【Luogu P2508】 [HAOI2008]圆上的整点
    【Luogu P1102】A-B 数对
  • 原文地址:https://www.cnblogs.com/binmengxue/p/6402067.html
Copyright © 2011-2022 走看看