A therapeutic «дебаунцер» so that the hover does NOT work too abruptly:

 $('p').text('Заработала страничка, сделай hover меня'); $('p').hover( function () { k=setInterval(show_tip('div'),2000); // <- почему нет задержки 2 сек?? }, function () { hide_tip('div'); }); function show_tip(target) {$(target).fadeIn(300);} function hide_tip(target) {clearInterval(k); $(target).fadeOut(300);} 

    1 answer 1

    @ Oleg B , because the argument for setTimeout and setInterval is a function and not undefined like yours :)

    hint: show_tip('div') will be executed immediately, because the script will try to calculate the argument for the setInterval function) (yesterday I answered exactly the same question)

    why don't you write in hover for some reason?

     $('p').hover( k=setInterval(show_tip('div'),2000); // <- почему нет задержки 2 сек?? , hide_tip('div'); ); 

    Here and in setInterval , it is also necessary to give the argument a function, not its result.

    • The link should be beaten http://hashcode.ru/questions/<qid>#<aid> - Yura Ivanov
    • one
      I just can’t get used to the fact that js is there instead of just a link ... - zb '
    • @eicto, everything would be fine, but only I have this there, and the construction is k = setInterval (function () {show_tip (this);}, 3000); Already as I understand it passes another this, mb there are some options? here is approximately how here: jsfiddle.net/alpha9000/nGaHh although I found the option: $ ('p'). hover (function () {mytarget = this; setTimeout (function () {show_tip (mytarget);}, 600); }, function () {hide_tip (this);}); - ferrari
    • 3
      @ Oleg B var do not forget. here you got mytarget into the global context without var . - Yura Ivanov