English 中文(简体)
jquery hover和停留到停用
原标题:jquery hover and stay until mouse out

I am trying to create a cart link where the shopping cart opens out on hover. I am able to get the cart to open out on hover and close when moving away. However I cannot get the cart block to stay open once hovered over. I would like the car block to open out on hover and stay open if you hover over it. You will see what I mean if you hover over the cart link in the top right corner of this page.

rel=“nofollow”http://dl.drop Box.com/u/4380589/Rococlothing/index.html

The jQuery I am using is:

jQuery( #cart-links .links .first a ).mouseover(function(){
  jQuery( .block-cart ).slideDown(400);
}).mouseout(function(){
  jQuery( .block-cart ).slideUp(400);
});

jQuery(".block-cart").mouseover(function(){
 jQuery(this).show();
}).mouseout(function(){
 jQuery(this).fadeOut("slow");
});
最佳回答
hovered = false;

jQuery( #cart-links .links .first a ).mouseover(function(){
    jQuery( .block-cart ).slideDown(400);
}).mouseout(function(){
      setTimeout(function(){
      if(!hovered) {
        jQuery( .block-cart ).slideUp(400);
      }}, 250);
   });

jQuery(".block-cart").mouseover(function(){
 hovered = true;
}).mouseout(function(){
 hovered = false;
 jQuery( #cart-links .links .first a ).trigger("mouseout");
});
问题回答

It looks like the .block-cart is not a child of the element that triggers the hover, so in order to keep the hover state active you d have to structure your HTML in a way that the .block-cart is a child element of the element that triggers the hover.

Btw: why don t you use $(this).hover() instead of $(this).mouseover().mouseout(), it s a little easier





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签