Jquery delay execution of script

前端 未结 2 524
故里飘歌
故里飘歌 2020-12-01 23:13

Having the following:

$(\'#navMain .nav1\').hover(function () {
    $(this).addClass(\'hover\');
    if ($.browser.msie && $.browser.version < 7)          


        
相关标签:
2条回答
  • 2020-12-01 23:33
    setTimeout( function(){
    
      // your stuff here
    
    }, 500); // delay 500 ms
    

    with your code:

    $('#navMain .nav1').hover(
    
      function () {
        setTimeout( function(){
            $(this).addClass('hover');
            if ($.browser.msie && $.browser.version < 7) $('select').css('visibility', 'hidden');
        }, 500); // delay 500 ms
      }, 
    
      function () {
        $(this).removeClass('hover');
        if ($.browser.msie && $.browser.version < 7) $('select').css('visibility', 'visible');
      }
    
    );
    
    0 讨论(0)
  • 2020-12-01 23:45

    If a simple javascript delay can help you, you can do as follow:

    setTimeout(function() {
      // your code here
    }, 3000);
    

    With the following signature: setTimout(functionToExecute, delayInMs);

    and the documentation: http://www.w3schools.com/js/js_timing.asp

    Hopping I help you.

    0 讨论(0)
提交回复
热议问题