2013-05-07 3 views
-1

Я нашел этот код. Он будет работать, когда вы перейдете к нижней части всей страницы. Я хочу изменить этот код, чтобы определить, когда внизу div.JQuery: сделать код, работая при прокрутке до конца div

И это код

$(window).data('ajaxready', true).scroll(function(){ 
if ($(window).data('ajaxready') == false) return; 
if($(window).scrollTop() == $(document).height() - $(window).height()) 
{ 
    var datastring=$(".passform").last().serialize(); 
    $('div#loadmoreajaxloader').show(); 
    $(window).data('ajaxready', false); 
    $.ajax({ 
    type: "POST", 
    url: "post_update.php", 
    data: datastring, 
    cache : false, 
    success: function(html) 
    { 
     if(html) 
     { 
      $("#update").append(html); 
      $('div#loadmoreajaxloader').hide(); 
     }else 
     { 
      $('div#loadmoreajaxloader').html('<center>No more posts to show.</center>'); 
     } 
     $(window).data('ajaxready', true); 
    } 
    }); 
}}); 

спасибо!

ответ

1

Вы можете сделать это:

Получить positon в нижней части DIV, как это:

var bottom = $('#myDiv').position().top + $('#myDiv').outerHeight(true); 

Comapre с $(window).scrollTop()

if($(window).scrollTop() == bottom) { 
    // We are the bottom of the div 
1

$ (окно) .height () даст вам высоту порта просмотра, до которой вы можете прокручивать страницу.

var vH = $(window).height(); 
$('#yourSelector').scroll(function() { 
    if ($(this).scrollTop() == vH) { 
     //Do ur work 
    } 
}); 
1

Мое мышление - перевернуть его вверх ногами в основном.

$(window).scroll(function() { 
    var targetDiv = $('#div1'); 

    //Get the Y position of the bottom of the div 
    var divBottom = (targetDiv.position().top + targetDiv.height); 

    //get the top position of the scroll, minus the bottom of the div 
    //and then minus the height of the window as the user can see that much 
    var invertedTop = ((divBottom - $(window).scrollTop()) - $(window).height()); 

    //Less than or = to means we are at the bottom of the div. 
    if (invertedTop <= 0) {console.log('You have reached the bottom of the target div');} 
     else {console.log('You have not reached the bottom of the target div yet.');} 
}); 
Смежные вопросы