How to tell .hover() to wait?

This will make the second function wait 2 seconds (2000 milliseconds) before executing: $(‘.icon’).hover(function() { clearTimeout($(this).data(‘timeout’)); $(‘li.icon > ul’).slideDown(‘fast’); }, function() { var t = setTimeout(function() { $(‘li.icon > ul’).slideUp(‘fast’); }, 2000); $(this).data(‘timeout’, t); }); It also clears the timeout when the user hovers back in to avoid crazy behavior. This is not a very … Read more

What advantage is there in using the $timeout in AngularJS instead of window.setTimeout?

In basic words $timeout refers to angularjs when setTimeout – to JavaScript. If you still think to use setTimeout therefore you need invoke $scope.$apply() after As a side note I suggest you to read How do I “think in AngularJS” if I have a jQuery background? post and AngularJS: use $timeout, not setTimeout Example 1: … Read more

Is setTimeout with no delay the same as executing the function instantly?

It won’t necessarily run right away, neither will explicitly setting the delay to 0. The reason is that setTimeout removes the function from the execution queue and it will only be invoked after JavaScript has finished with the current execution queue. console.log(1); setTimeout(function() {console.log(2)}); console.log(3); console.log(4); console.log(5); //console logs 1,3,4,5,2 for more details see http://javascriptweblog.wordpress.com/2010/06/28/understanding-javascript-timers/

Call setTimeout without delay

Very simplified: Browsers are single threaded and this single thread (The UI thread) is shared between the rendering engine and the js engine. If the thing you want to do takes alot of time (we talking cycles here but still) it could halt (paus) the rendering (flow and paint). In browsers there also exists “The … Read more

What is the equivalent of javascript setTimeout in Java?

Asynchronous implementation with JDK 1.8: public static void setTimeout(Runnable runnable, int delay){ new Thread(() -> { try { Thread.sleep(delay); runnable.run(); } catch (Exception e){ System.err.println(e); } }).start(); } To call with lambda expression: setTimeout(() -> System.out.println(“test”), 1000); Or with method reference: setTimeout(anInstance::aMethod, 1000); To deal with the current running thread only use a synchronous version: … Read more