js滚动条向下

需要jquery

 


<html> 
<head>
	<script type="text/javascript" src="jquery-2.1.1.js"></script>
</head>
<body>
            <div id="scrolldIV" style="overflow:auto; height: 100px; width: 400px; border: 1px solid #999;">
            </div>
            <input type="button" value="插入一行" onclick="add();">     
	        <script type="text/javascript">
                var t=true;
                function add()
                {
                    var now = new Date(); 
                    var div = document.getElementById('scrolldIV');
                    div.innerHTML = div.innerHTML + 'time_' + now.getTime() + '<br />'; 
                    if(t)  
                    div.scrollTop = div.scrollHeight;         
                }
				$("#scrolldIV").scroll(function(){
					var scrollHeight = document.getElementById("scrolldIV").scrollHeight;//251
					var scrollTop = document.getElementById("scrolldIV").scrollTop;//0-18
					var clientHeight = document.getElementById("scrolldIV").clientHeight;//233
                    var div = document.getElementById('scrolldIV');
					console.log(scrollHeight);
					if (scrollHeight - clientHeight == scrollTop) {
                        t=true;	    
					}

                    var agent = navigator.userAgent;
                if (/.*Firefox.*/.test(agent)) {
                        document.addEventListener("DOMMouseScroll", function(e) {
                        e = e || window.event;
                        var detail = e.detail;
                    if (detail > 0) {
                        console.log("鼠标向下滚动");
                    } else {
                        t=false;
                    }
                    });
                } else {
                    document.onmousewheel = function(e) {
                    e = e || window.event;
                    var wheelDelta = e.wheelDelta;
                    if (wheelDelta > 0) {
                        t=false;
                    } else {
                    console.warn("鼠标向下滚动");
                    }
                    }
                }

				})
            </script>
</body>
</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值