With strange reasons $(window).scroll() not working. I am working on this for a while but I can't figured out what silly thing I am doing in it.
fiddle
$(document).ready(function(){
// fill body with data so we can see the scroll
for(var i=0; i<1000; i++)
{
$('#list').append(i+'<br>');
}
// jQuery plug-in
$(window).scroll(function(){
if($(window).scrollTop() == 800)
{
alert('mission acplished');
}
});
});
Console error
TypeError: window.scrollTop is not a function
thanks in advance!
With strange reasons $(window).scroll() not working. I am working on this for a while but I can't figured out what silly thing I am doing in it.
fiddle
$(document).ready(function(){
// fill body with data so we can see the scroll
for(var i=0; i<1000; i++)
{
$('#list').append(i+'<br>');
}
// jQuery plug-in
$(window).scroll(function(){
if($(window).scrollTop() == 800)
{
alert('mission acplished');
}
});
});
Console error
TypeError: window.scrollTop is not a function
thanks in advance!
Share Improve this question asked Feb 27, 2014 at 6:00 Aamir ShahzadAamir Shahzad 6,8348 gold badges48 silver badges72 bronze badges 1- 4 It works just fine. You're probably not getting the expected result, because you will never hit exactly 800. Try using >= 800 - Fiddle – Bic Commented Feb 27, 2014 at 6:03
1 Answer
Reset to default 9Check this http://jsfiddle/KHeZY/39/
It is not always necessary that $(window).scroll()
stops at 800, this event only triggers after you stop scrolling $(window).scrollTop()
you need to set some window for it.
$(window).scroll(function(){console.log($(window).scrollTop());
if($(window).scrollTop() > 800 && $(window).scrollTop() < 850)
{
alert('mission acplished');
}
});