1

这是浮动的 div xwiki-controls 工作时

$(window).scroll(function() {
        var scrollTop = $(window).scrollTop();

或者$(document).scroll(function() { var scrollTop = $(document).scrollTop();

但不要这样工作

$(document).ready(function() {
    var nav = $('.xwiki_controls');
    var isFixed = false;
    $('#parag').scroll(function() {
        var scrollTop = $('#parag').scrollTop();
        var shouldBeFixed = scrollTop > 250;
        ...
4

1 回答 1

0

This is a sample of code which I have tested. Hope it will help you.

This is used to stick the div on top.

$(document).ready(function(){
     var p = $("#stop").offset().top;

    $(window).scroll(function(){
        if(p<$(window).scrollTop()){
            console.log("div reached");
            $("#stop").css({position:"fixed",top:0});
        }
        else{
            console.log("div out");
            $("#stop").css({position:"static"});
        }

    })
});
于 2013-07-26T14:35:20.490 回答