0

These is main function

function isScrolledIntoView(elem)
    {

        var docViewTop = $(window).scrollTop();


        var elemBottom = elemTop + $(elem).height();

        if (elemBottom >=docViewTop) {
            return true
        }
        else {
            return false
        };
    }

This is delayed

var timeoutSrc
    function delayedSrc(elem){
        timeoutSrc=window.setTimeout(isScrolledIntoView(elem), 2200)}

Here I call it:

delayedSrc($("#result"));

But by alert test message I can tell, that there is no delay.

Joe Half Face
  • 2,303
  • 1
  • 17
  • 45

1 Answers1

3

You're calling the function, then passing it to setTimeout. One way to fix this:

var timeoutSrc;

function delayedSrc(elem){
    timeoutSrc= window.setTimeout(function () {
        isScrolledIntoView(elem);
    }, 2200);
}
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • 2
    Although I had you by exactly 1 second, I will concede that your answer is superior with your judicious use of semicolons. Well played, sir. :) – Rob Hruska May 07 '13 at 03:01
  • I'm laughing, but I'm also shaking my head that this question doesn't have most close votes. – Matt Ball May 07 '13 at 03:02
  • 1
    It's always difficult to find the *exact* dupe for these, since they're all pretty localized. [This one is close](http://stackoverflow.com/questions/3264963/settimeout-not-working-with-jquery), but not quite. – Rob Hruska May 07 '13 at 03:04
  • @RobHruska I think [that](http://stackoverflow.com/questions/16410590/spam-spam-spam-spam#comment23528297_16410590) counted as a close with prejudice. `:)` – Matt Ball May 07 '13 at 03:15
  • Lol, yeah, we owned that one. – Rob Hruska May 07 '13 at 03:16