How can I get the position of an element with jQuery after a successful Ajax Call? [closed]
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()
;-)
精彩评论