0

$(element).scroll(function(){}); 関数をjsファイルに入れると機能しませんが、コンソールに入力すると(スクロール機能だけ)、問題なく機能します。

スクロールページ付けを実行しようとしています。

私は他のjsファイルを調べましたが、競合している可能性があるのは、別のファイルに$(document).ready(function(){})があることだけですが、それは問題ではないと確信しています。 。私もDropkickを使ってかなりのドロップダウンを作っていますが、それでもそうだとは思いません。

これがほぼ逐語的なコードです。ロードする方法がわかるまでは、今のところ基本です。

$('#main').scroll(function(){
    if(($('#main').prop('scrollHeight'))==
        ($('#main').scrollTop()+$(document).height()-10)){
        //^there's a strange 10px empty space that needs to be accounted for
        $('#loading').show();
        $('#main').css('overflow','hidden');
        addMore();
    }
});
$(document).ready(function(){
    addMore();
});
addmore.counter=0;
function addMore(){
    $.ajax({
    async: 'true',
    url: 'http://mywebsite.com/bc/get',
    type: 'post',
    data: ({'offset':(addmore.counter)}),
    success: function(data) {
        $('#scrollingpagination').append(data);
        $('#loading').hide();
        $('#main').css('overflow','scroll');
        addmore.counter++;
    }
    });
}

そしてここにHTMLがあります(逐語的ではありませんが、同じ考えです)

<!--I'm only including the "main" div that shows the content.-->
<div id='main'>
    <div id='scrollingpagination'></div>
    <div id='loading'></div>
</div>

みんなありがとう、本当に感謝しています!

4

1 に答える 1

0

維持してみてください

$('#main').scroll(function(){
            ......
}) 

document.ready。domの準備が整う前に呼ばれたと思います

于 2012-12-17T09:52:55.083 に答える