首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

js 判断滚动条的高度位置,该怎么处理

2012-12-24 
js 判断滚动条的高度位置//这个是根据滚动条分批加载方法,滚动条拉到底部触发window.onscroll function

js 判断滚动条的高度位置
//这个是根据滚动条分批加载方法,滚动条拉到底部触发
window.onscroll = function () {
    var winScroll = document.documentElement.scrollTop || document.body.scrollTop;
    if (winScroll == (document.body.offsetHeight - document.documentElement.clientHeight)) {
       alter("触发事件了");
          }
}

现在的效果是 ,滚动条必须拉到底部才触发。
我想要的效果是 离底部还有 100 px 的时候触发,就是离底部还有一点距离触发
[解决办法]
拜托了,在线等...
[解决办法]
比如你的滚动条在1个div里
那么就是 document.getElement("divID").offsetWidth 这个是获取你目测 这个滚动条的一个高度

如果你想获取 垂直滚动条的 滚动的距离 

document.getElement("divID").scrollTop 来获取!
[解决办法]
(document.body。scrollTop + 100) 跟 document.documentElement.clientHeight 比较下
[解决办法]
(document.body。scrollTop + 100) 跟 document.documentElement.clientHeight

是 100 跟 699
[解决办法]
求救...
[解决办法]

<a id="gotopbtn" style="position:fixed;width:12px;bottom:95px;right:195px !important;display:none;cursor:pointer; _position: absolute;_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight - this.offsetHeight)); _background:none; display:none;)">返回顶部</a>
                                <script type="text/javascript">goTopEx();</script>
                                <script type="text/javascript">
                                    function goTopEx() {
                                        var obj = document.getElementById("gotopbtn");
                                        function getScrollTop() {
                                            return document.documentElement.scrollTop 
[解决办法]
 document.body.scrollTop;
                                        }


                                        function setScrollTop(value) {
                                            if (document.documentElement.scrollTop) {
                                                document.documentElement.scrollTop = value;
                                            } else {
                                                document.body.scrollTop = value;
                                            }
                                        }
                                        obj.onclick = function () {
                                            var goTop = setInterval(scrollMove, 1);
                                            function scrollMove() {
                                                setScrollTop(getScrollTop() / 1.1);
                                                if (getScrollTop() < 1) clearInterval(goTop);
                                            }
                                        }


                                        //让返回顶部标签,始终停在footer 之前!    
                                        var btmHeight = (-[1, ]) ? 340 : 350;
                                        window.onscroll = function () {
                                            getScrollTop() > 0 ? obj.style.display = "" : obj.style.display = "none";
                                            obj.style.bottom = 85 + "px";
                                            if (getDisFromBottom() <= btmHeight) {
                                                obj.style.bottom = getDisFromBottom() + "px";
                                                obj.style.top = "auto";
                                            }
                                        }
                                        function getDisFromBottom() {
                                            var dis = getScrollTop() + getClientHeight() + btmHeight - getScrollHeight();
                                            return dis > 85 ? dis : 85;


                                        }
                                        function getScrollHeight() {
                                            return getDocEle().scrollHeight;
                                        }
                                        function getClientHeight() {
                                            return getDocEle().clientHeight;
                                        }
                                        function getDocEle() {
                                            return document.compatMode == 'CSS1Compat' ? document.documentElement : document.body;
                                        }
                                    }
                                </script>



看看这段代码 能帮助你么
[解决办法]
继续等待...
[解决办法]
救命呀,来人...
[解决办法]
等到花儿都谢了

热点排行