开发者

How can I get the position of an element with jQuery after a successful Ajax Call? [closed]

开发者 https://www.devze.com 2023-02-03 02:32 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

I am trying to create sort of a lazyloaded event with jQuery upon the container being scrolled to a certain position. This is supposed to happen after a successful ajax request, but I am having trouble getting the code to work here. Here is my code:

$.ajax({
    url: load.php,
    type: 'GET',
    cache: true,
    success: function(da开发者_运维百科ta) {
        $('#container').html(data)
    }
    });


$('#container').live('scroll', function() {  
var position = $("#load").offset().top;          
var scrollPosition = $('#container').height(); +$('#container').scrollTop();
if ( scrollPosition > position) {
     alert( "ALERT" );
                              }
});

Can anyone help me out here please. Any help would be greatly appreciated.


Try this:

$.ajax({
    url: load.php,
    type: 'GET',
    cache: true,
    success: function(data) {
        $('#container').html(data);
    }
});


$('#container').live('scroll', function() {  
    var position = $("#load").offset().top;
    var scrollPosition = $('#container').height() + $('#container').scrollTop();
    if ( scrollPosition > position) {
        alert( "ALERT" );
    }
});

What did I change? Formatting mostly, but also removed an extra ; after $('#container').height() ;-)

0

精彩评论

暂无评论...
验证码 换一张
取 消