Search code examples
javascriptjquerydelayqtip

how to delay() qtip() tooltip to be loaded


I Load this way:

$('.selector').each(function(){
$(this).qtip({
     content: { url: '/qtip.php?'+$(this).attr('rel')+' #'+$(this).attr('div'), text:'<center><img src="/images/loader.gif" alt="loading..." /></center>'  },

     show: { delay: 700, solo: true,effect: { length: 500 }},
     hide: { fixed: true, delay: 200 },

     position: {
     corner: {
        target: 'topRight',
        tooltip: 'left'
                }
                },
                show: {
          // Show it on click
         solo: true // And hide all other tooltips
      },
     style: {
       name: 'light',
       width: 730,border: {
         width: 4,
         radius: 3,
         color: '#5588CC'
      }    
       } 
   });

});

And that looks like if there is a thelay cause of the effect. but qtip.php it's loaded with no delay which is what I really want (to reduce unneeded requests)

Can I delay 300ms before loading qtip.php?


Solution

  • You could set it to use a custom event, then trigger the event after a timeout. The hoverIntent plugin might help, if you want to wait until the mouse stops.

    Using hoverIntent:

    $(selector).hoverIntent(function() {
        $(this).trigger('show-qtip');
    }, function() {
        $(this).trigger('hide-qtip');
    }).qtip({
        // ...
        show: {
            when: { event: 'show-qtip' }
        },
        hide: {
            when: { event: 'hide-qtip' }
        }
    });
    

    If you want to make hoverIntent wait longer before triggering, you can give it a configuration object with an interval property:

    $(selector).hoverIntent({
        over: showFunction,
        out: hideFunction,
        interval: 300 // Don't trigger until the mouse is still for 300ms
    });
    

    Without a plugin (I haven't tested this):

    (function() { // Create a private scope
        var timer = null;
        var delay = 300; // Set this to however long you want to wait
    
        $(selector).hover(function() {
            var $this = $(this);
            timer = setTimeout(function() {
                $this.trigger('show-qtip');
            }, delay);
        }, function() {
            if (timer) {
                clearTimeout(timer);
            }
        }).qtip({
            // ...
            show: {
                when: { event: 'show-qtip' }
            }
        });
    })();