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();
  • 相关阅读:
    cad.net 仿lisp函数专篇
    操作篇 cad一个小技巧,通过块中块插入含有字段块,保证更新
    cad.net 外部参照功能和相对路径转换
    cad.net 动态块名 .IsDynamicBlock出错 eInvalidObjectId错误.
    cad.net 委托的学习
    cad.net 关于保存文件Database.SaveAs()出现"eFileAccessErr"错误的解决方法
    测试篇 c# winFrom Close报错 System.ObjectDisposedException:“无法访问已释放的对象。
    测试篇 c#枚举类型怎么用?
    cad.net 2008使用WPF(摘录山人)
    日志篇 随着win10更新...
  • 原文地址:https://www.cnblogs.com/binmengxue/p/6402067.html
Copyright © 2011-2022 走看看