setTimeout or setInterval?

0

I'm using a tooltip plugin in jQuery to modify attributes title="" of various classes. It was working fine until I realized a problem - I am using a button that changes class as it is clicked, and when this button changes class the tooltip stops working.

It's obvious that I've tried adding the class of the button to which it changes after clicking on the same function as tooltip in JavaScript, but this did not work.

So my solution to this was to use setInterval() to run this function from x to% with% time so that the tooltip would run again after the class of this button has been modified.

But now I have 2 questions:

  • When we use x the request for this function is being sent to the server each time it tries to run again, or it is only running in its own Browser Window

asked by anonymous 26.05.2015 / 19:28

2 answers

3

This plugin already has options to do this. The syntax syntax is:

  

$ ('# example-delay') tipsy ( delayIn : 500, delayOut : 1000});

An example would be:

$('.like-button').tipsy({
    fade: true,
    gravity: 'w',
    delayIn: 500,    // pausa antes de abrir
    delayOut: 1000   // pausa antes de voltar a fechar
});

Example: link

Of the two solutions you had setInterval was a bad idea because you run the code indefinitely without need.

Note / request for clarification:

In your question you refer "to be sent to the server" and "modify title attributes of various classes" . Your code does not reflect that, hence my response to the documentation. If the answer is not what you were looking for try to be more specific. Usually using setInterval in this case or in case of communication with the server is rarely the right solution.

    
26.05.2015 / 19:41
1

I was able to solve the problem - checking if the parent / wrapper div has the mouse inside it using .hover() instead of $( document ).ready() which is suggested by the plugin

For example:

$(".parent-wrapper").hover(function() {
    $('.like-button').tipsy({fade: true, gravity: 'w'});
});
    
26.05.2015 / 23:41