Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8697087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:25:56+00:00 2026-06-13T01:25:56+00:00

So my script works but the issue I am having is that when i

  • 0

So my script works but the issue I am having is that when i use the close-but function it hides the div, but after a few seconds the div slidesdown. Am I missing something with like a if statement? Thank you.

$(document).ready(function() {
    $(".cart").hover(function() {
        $(".dropcart").slideDown('slow');
     });
    $('.dropcart').mouseleave(function() {
        $('.dropcart').css({
            'opacity': '.5'
        }, setTimeout(function() {
            $('.dropcart').slideUp('slow');
        }, 3000));
         });
    $('.dropcart').mouseenter(function() {
        $('.dropcart').css({
            'opacity': '1'
        });
    });
        $('.close-but').click( function() {
    $('.dropcart').hide();
    });
    });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:25:57+00:00Added an answer on June 13, 2026 at 1:25 am

    hover is a shorthand for the mouseenter/mouseleave handlers (see: http://api.jquery.com/hover/).

    I tend not to use hover for more complex interactions since, as you’ve discovered, there are some quirks to how the event handler works. I’ve found that binding an event handler to hover fires the handler twice. Instead, what you should do is:

    $('.cart').mouseenter( function(){
        // Your state behaviour code here..
    } ).mouseleave( function(){
        // Your state behaviour code here...
    } );
    

    One think you might want to consider using is jquery’s livequery plugin, which improves event binding/handling for DOM elements. So, your example could be refactored to look something like this:

    Edits:
    Changed pathing to find the parent element that contains both .cart and .dropcart

    $('.cart').livequery( function(){
        var obj      = $( this ).closest('.float-left'); // The cart container element
        var dropcart = obj.find('.dropcart'); // Child of .float-left
        var close    = dropcart.find('.close-but');  // Child of dropcart
    
        // Handle cart mouseenter event
        obj.mouseenter( function(){
            dropcart.slideDown(300);
        } );
    
        // Handle cart moseenter/mouseleave events
        dropcart.mouseenter( function(){
            // your behaviour here...
        } ).mouseleave( function(){
            // your behaviour here...
            // Read up on jQuery's delay() method: http://api.jquery.com/delay/
            dropcart.delay(800).slideUp(256);
        } );
    
        // Handle the close button
        close.click( function(){
            dropcart.hide(); // or dropcart.mouseleave(); // triggers the mouseleave event handler
        } );
    
    } );
    

    Update

    I didn’t see the fiddle in the initial comments, and now that I understand the structure, I’ve revised the examples above to reflect (see revisions above). A couple additional things I would also recommend doing:

    1. Add an ID or common class to the containing element, e.g.
      class="cart-container float-left" or id="cart-container"
    2. Consider refactoring the markup to be a little more semantic considering the content that appears in there. (I know some folks would argue that there’s little value in doing that with JS enhanced features, but I still think it’s a good habit to get into).

    An example of the html refactoring would be:

    <div class="item-container right">
        <img src="http://news.worldwild.org/wp-content/uploads/2008/09/red_panda.jpg">
    
        <div class="cart-items">
            <h3>Cart Items: <span class="cart-items-count">10</span></h3>
            <div class="dropcart">
                <dl class="cart-items-list">
                    <dt>Items:</dt>
                    <dd>10</dd>
                    <dt>Price:</dt>
                    <dd>$5.00</dd>
                </dl>
                <a href="#" class="close" title="close">x</a>
            </div>
        </div>
    </div>​
    

    Supporting CSS:

    .right {
        float: right;
    }
    
    .item-container > img {
        display: block;
        margin: 0 0 10px 0; padding :0; 
        border: 0;
    
        width: 100px; height: auto;
    }
    
    .item-container .cart-items {
        display: block;
        background: #222;
        color: #fff;
    }
    
    .cart-items {
        display: block;
        margin: 0; padding :0; 
    }
    
    .cart-items > h3 {
        cursor: pointer;
    }
    
    .cart-items-list dt {
        display: inline;
        float: left;
        clear: right;
    }
    
    .cart-items-list dd {
            text-align: right;
    }
    
    .dropcart .close {
        display: block;
        padding: 0 10px;
    
        font-weight: bold;
        text-align: right;
    
        color: #fff;
    }​
    

    Your jQuery script would be something like:

    jQuery( function(){
    
        $('.item-container').livequery( function(){
            var obj      = $( this ).find('.cart-items'); // The cart container element
            var dropcart = obj.find('.dropcart'); // Child of .float-left
            var close    = dropcart.find('.close');  // Child of dropcart
    
            dropcart.hide();
    
            // Handle cart mouseenter event
            obj.mouseenter( function(){
                dropcart.slideDown(300);
            } );
    
            // Handle cart moseenter/mouseleave events
            dropcart.mouseenter( function(){
                // your behaviour here...
            } ).mouseleave( function(){
                // your behaviour here...
                // Read up on jQuery's delay() method: http://api.jquery.com/delay/
                dropcart.slideUp(256);
            } );
    
            // Handle the close button
            close.click( function(){
                dropcart.mouseleave( function(e){ return false; }); // triggers the mouseleave event handler
                dropcart.hide();
            } );
    
        } );
    
    } );
    ​
    

    You can see it in action here: http://jsfiddle.net/kwbbh/2/ (forked the OPs fiddle)
    ​

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this script that works, but I need to change the format of
I have a simple images resizing script that works great for JPEGs, but not
I'm having issues with a script that I made for use in HTML5. Here
This script works fine on single click but on double click it shows both
My script works seemed to be working perfectly well, but Eclipse 3.7.2 was telling
The following script works for me, but I wonder if it could be done
The script below works fine if 3 and 3.2 are not links but i
I just finished this script it works well, but I am struggling to pass
I have written a script which works, but I'm guessing isn't the most efficient.
Why doesn't this work <script src=jquery.js/> But this works <script src=jquery.js></script> ? Firefox 3.5.8

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.