jquery 滚动条 触发事件

1。监听某个元素的滚动条事件
$(selector).scroll(function(){.......});

2.获取滚动条滚动的距离
$(selector).scrollTop();
$(selector).scrollLefft();

3.滚动条事件和offset方法的应用
实例1. 随浏览器滚动条而滚动的浮动div。例图: Jquery滚动条事件的处理 - 天马hygj - Nothing
代码:
        #floatRight {
            position:relative; 
            float:right; 
            width:200px; height:200px; background-color:green;
            top:100px;
            z-index:1000;
        }
            //滚动条滚动事件1
            var oldSite=new Object();
            oldSite.left=$("#floatRight").offset().left;
            oldSite.top=$("#floatRight").offset().top;
            $(window.document).scroll(function () {
                var scrolltop = $(document).scrollTop();
                var top=oldSite.top+scrolltop;
                $("#floatRight").offset({ top: top });
            });
实例2.虽dom元素内滚动条滚动而滚动的浮动div
实例图
Jquery滚动条事件的处理 - 天马hygj - Nothing

         #content {
            width:600px; height:1000px; border:2px dotted red;
            overflow:scroll;
            margin:auto;
        }
        #contentFloat {
            float:right;position:relative;
            width:100px; height:100px; background-color:green;
            top:100px;
        }

            //滚动条滚动事件2
            var contentFloat = $("#contentFloat");
            var top = contentFloat.offset().top;
            $("#content").scroll(function () {
                contentFloat.offset({top:top});
            });
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值