触发仅在页面加载时滚动时触发的事件

时间:2014-12-01 13:23:57

标签: jquery

我想触发一个只在滚动时触发的功能,这可能吗?

$(document).ready(function() 
    $(document).scroll(function() {
        // do something here
    });

    // here I want to trigger the scroll function (without scrolling)
});

我尝试$(document).scroll();但没有成功:

$(document).ready(function() 
    $(document).scroll(function() {
        // do something here
    });
    $(document).scroll();
});

1 个答案:

答案 0 :(得分:1)

将其更改为使用命名函数:

$(document).ready(function() 
    $(document).scroll(onScroll);

    onScroll();
});

function onScroll() {
}

现在该函数已命名,您可以随时自由执行该代码。