Have read that it is possible to detect a scroll with this line:
$('window').one('scroll', function() { } );
If have this inline code:
var TimeVariable=setInterval(function(){ DoJQueryStuff() },300);
function DoJQueryStuff()
{
if(typeof jQuery == "undefined") return;
window.clearInterval(TimeVariable);
$('body').one('mousemove', function() { alert('mouse'); } );
$('window').one('scroll', function() { alert('scroll'); } );
}
DoJQueryStuff is called every 300 ms until JQuery is loaded. If I move the mouse anywhere on the screen, I got the "mouse" alert. If I scroll down I do NOT get the "scroll" alert. i.e. it's not firing.
Any help would be greatly appreciated.
David
first please use jquery
readyhttp://api.jquery.com/ready/ method. i dont want to say your implementation is wrong but is slower than the jquery ready method.your scroll function don't get executed basically because you are binding it to the wrong object. when you refer to the
windowobject with jquery don't wrap it in apostrophs.if you do so, jquery will intern call the
document.getElementsByTagNameand can't find the tagnamewindowbecausewindowis not an child of thewindow.documentnode. so your scroll detect function never gets fired because jquery can't bind aeventListenerto your submited element tagname.simply bind it to
windowwithout apostrophs. this forces jquery to bind the scroll event directly to thewindowDOM object where your function is correctly fired on scroll.Example: