我无法理解脚本是如何工作的,我可以做些什么来改进它,缩小等。我还想找到一种附加按钮的方法,这将停止该功能(有点禁用自动加载内容按钮), 你有什么主意吗?这是代码:(对我来说最重要的部分是理解代码)
var page = 1;
var pageLast = 1;
var stop = false;
function lastPostFunc()
{
$('div#loading').html('loading data ...') ;
page += 1;
if (page+1 > pageLast) {
stop=true;
}
var objURL = new Object();
window.location.search.replace(
new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),
function( $0, $1, $2, $3 ){
objURL[ $1 ] = $3;
}
);
q = '?strona='+page
for (var k in objURL){
if (k != 'strona' )
q += ('&'+k+'='+objURL[ k ])
}
data = $('<div/>').load( "/shop/category/example/" + q +' #produkt_lista',function() {
$('.produkt .opis',$(this)).each( function() { $(this).css('display', 'none'); } );
$('a.jt').cluetip({ cluetipClass: 'jtip', arrows: true, dropShadow: false, hoverIntent: false, sticky: false, mouseOutClose: true, showTitle: false, closeText: 'zamknij', width: 300, positionBy: 'mouse', topOffset: 0});
});
if (data != "") {
$('.paginator').hide();
$("#produkt_lista").append(data);
}
$('div#loading').empty();
};
$(document).ready(function() {
pageLast = parseInt( $('.paginator .paginate-pages').first().text().replace('Stron: ',''));
$('#produkt_lista').after( $('<div id="wczytywanie" style="display: none; font-weight: bold; font-size: 20px; line-height: 40px; color: red; margin: 20px auto; width: 300px; border: 1px solid red;"></div>') );
$(window).scroll(function(){
if ($(window).scrollTop()+200 > $(document).height() - $(window).height()){
if (!stop) lastPostFunc();
}
});
} );