[jQuery] Re: setTimeout / clearTimeout question...

2008-01-24 Thread gr00vy0ne

David,

Thank you so much for the suggestion. As you expected, it worked
perfectly for me. I ended up with the following:

function addHoverHide(linkClass, layerId) {
var t;
$(a. + linkClass).hover(function() {
clearTimeout(t);
// custom function which creates drop shadows around layerId
createShadowbox(layerId,this);
}, function() {
t = setTimeout(function() {$(# + layerId).hide()}, 1500);
});

// if user hovers over the floating layer
$(#+layerId).hover(function() {
clearTimeout(t);
}, function() {
t = setTimeout(function() {$(# + layerId).hide()}, 1500);
});
}

Thanks again!
-victor

On Jan 23, 7:09 pm, David Serduke [EMAIL PROTECTED] wrote:
 How about using closure like this?

 function addHoverHide(linkClass, layerId) {
   var t;
   $(. + linkClass).hover(function() {
 clearTimeout(t)
 $(# + layerId).show();
   }, function() {
 t = setTimeout(function() {$(# + layerId).hide()}, 2000);
   });}

 $(document).ready(function () {
   addHoverHide(some_link, this_layer);
   addHoverHide(some_other_link, this_other_layer);

 });

 Untested but the idea should work.  Good luck.

 David

 On Jan 23, 6:42 pm, gr00vy0ne [EMAIL PROTECTED] wrote:

  This is more of a general javascript question but when using
  setTimeout and clearTimeout, does the timer variable have to exist
  outside the function globally?

  For instance, I understand the following:

  var t;

  $(.some_link).hover(function() {
  clearTimeout(t)
  $(#this_layer).show();}, function() {

  t = setTimeout(function() {$(#this_layer).hide()}, 2000);

  }

  Is there a way to create the timer within the jquery hover so that
  it's self-contained? Ideally, I'd like the timer to be dynamically
  created as necessary so if I add other hovers then I don't need to
  keep adding new variables to store the timer.

  Would I have to create an array that stores each unique timer? Is that
  the way to go?


[jQuery] Re: setTimeout / clearTimeout question...

2008-01-23 Thread David Serduke

How about using closure like this?

function addHoverHide(linkClass, layerId) {
  var t;
  $(. + linkClass).hover(function() {
clearTimeout(t)
$(# + layerId).show();
  }, function() {
t = setTimeout(function() {$(# + layerId).hide()}, 2000);
  });
}
$(document).ready(function () {
  addHoverHide(some_link, this_layer);
  addHoverHide(some_other_link, this_other_layer);
});

Untested but the idea should work.  Good luck.

David

On Jan 23, 6:42 pm, gr00vy0ne [EMAIL PROTECTED] wrote:
 This is more of a general javascript question but when using
 setTimeout and clearTimeout, does the timer variable have to exist
 outside the function globally?

 For instance, I understand the following:

 var t;

 $(.some_link).hover(function() {
     clearTimeout(t)
     $(#this_layer).show();}, function() {

     t = setTimeout(function() {$(#this_layer).hide()}, 2000);

 }

 Is there a way to create the timer within the jquery hover so that
 it's self-contained? Ideally, I'd like the timer to be dynamically
 created as necessary so if I add other hovers then I don't need to
 keep adding new variables to store the timer.

 Would I have to create an array that stores each unique timer? Is that
 the way to go?