?
Solved

JQuery MouseLeave Function

Posted on 2014-08-27
11
Medium Priority
?
402 Views
Last Modified: 2014-09-22
Hi,

I'm trying to add a Mini Basket Preview to my site, easier said than done. I have 2 divs, one shows the basket summary and then another hidden one drops down with the preview when you hoiver over the summary, its then suppossed to stay there whilst you are in either and move back up after 3-4 seconds when you leave both. Could somebody advise on the below.

$(function () {

    var timeout;
    $(".col4").hoverIntent(function () {
        $("#ddContent").slideDown(800);
        clearTimeout(timeout);
    });

    $("#ddContent").hoverIntent(function () {
         $("#ddContent").slideDown(800);
        clearTimeout(timeout);
    });

    $("#ddContent,.col4").stop().mouseleave(function () {
        timeout = setTimeout(function () {
            $("#ddContent").slideUp(800);
        }, 2000);
    });
});

Open in new window

0
Comment
Question by:Karl Blackburn
  • 5
  • 5
11 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 40289395
you did not post your HTML.
the issue is most of time due to the HTML, for example when you decide to put child outside parent, I mean the dropdown and its items
0
 

Author Comment

by:Karl Blackburn
ID: 40289875
Slight change. I know have

<div id="basketholder">
<div id="col4" class="col4" style="overflow:visible">

<asp:UpdatePanel runat="server">
<contenttemplate>
<div class="baskettitle"><asp:HyperLink ID="LblBasketTitle" runat="server" NavigateUrl="basket.aspx">My Basket</asp:HyperLink></div>
<div class="basketcontent"><asp:HyperLink ID="LabelBasket" runat="server" NavigateUrl="basket.aspx"></asp:HyperLink></div>
</contenttemplate>
</asp:UpdatePanel>

<div style="position:relative;height:1px">
<img id="shoppingdot" src="images/siteassets/standard/shoppingbasketbutton.png" style="position:absolute;top:74px; right:80px;z-index:10001" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="DivBasketAdd" class="minibasket">
<asp:Literal ID="LtlMiniAdd" runat="server"></asp:Literal>
</div>
<div id="ddContent" class="minibasket">
<asp:Literal ID="LtlMiniCart" runat="server"></asp:Literal>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>

</div>
</div>

Open in new window


$(function () {

    var timeout;
    $("#basketholder,#LblBasketTitle,#LabelBasket,#ddContent, #shoppingdot").hoverIntent(function () {
        $("#ddContent").slideDown(800);
        clearTimeout(timeout);
    });

    $("#basketholder,#ddContent,#col4").stop().mouseleave(function () {
        setTimeout(function () {
            $("#ddContent").delay(500).slideUp(1200);
        }, 2000);
    });
});

Open in new window

0
 
LVL 43

Expert Comment

by:Rob
ID: 40289892
Given it's more a javascript question that asp, would you mind posting the rendered html rather than the asp markup please?
Load the page in the browser, right click, view source and copy and paste that.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Karl Blackburn
ID: 40289902
See below

<div id="basketholder">
<div id="col4" class="col4" style="overflow:visible">

<div id="ctl00_ctl10">
	
<div class="baskettitle"><a id="ctl00_LblBasketTitle" href="basket.aspx">My Basket</a></div>
<div class="basketcontent"><a id="ctl00_LabelBasket" href="basket.aspx">22 items<br>£243.42</a></div>

</div>

<div style="position:relative;height:1px">
<img id="shoppingdot" src="images/siteassets/standard/shoppingbasketbutton.png" style="position:absolute;top:74px; right:80px;z-index:10001" />
<div id="ctl00_UpdatePanel1">
	
<div id="DivBasketAdd" class="minibasket">

</div>
<div id="ddContent" class="minibasket">
<div class="minibasketinner"><div class="header">BASKET PREVIEW</div><table style="width:96%; margin-left:6px" cellpadding="4"><tr><td><a href="details.aspx?PID=8205"><img src="http://www.metoyouonline.com/images/product1/G01W1546.jpg" width="60px" /></a></td><td style="text-align:left"><a href="details.aspx?PID=8205">2 x 4" Silver Wedding Anniversary Me to You Bear   <br>Qty : 18</a></td><td>£233.82</td></tr><table style="width:96%; margin-left:6px" cellpadding="4"><tr><td><a href="details.aspx?PID=9300"><img src="http://www.metoyouonline.com/images/product1/A77TS040.jpg" width="60px" /></a></td><td style="text-align:left"><a href="details.aspx?PID=9300">Wife Anniversary Me to You Bear Card  <br>Qty : 4</a></td><td>£9.60</td></tr><tr><td colspan="3" style="height:20px; border-top:2px solid #9ed6f5; text-align:right; color:#de006e; font-weight:bold">TOTAL : £243.42</td></tr><tr><td colspan="3"><a href="basket.aspx"><img src="images/siteassets/minibasket_viewbasket.jpg" width="110" height="25"></a><a href="basketoffers.aspx"><img src="images/siteassets/minibasket_checkout.jpg" width="118" height="25"></a></td></tr></table></div>
</div>

</div>
</div>

</div>
</div>

Open in new window


Many thanks
0
 
LVL 43

Expert Comment

by:Rob
ID: 40289947
I think it's this simple: http://jsbin.com/yiwife/2/edit

$(function () {

	var timeout;
	$("#ctl00_ctl10").hoverIntent(
		function() {
			$("#ddContent").delay(500).slideUp(1200);
		},
		function() {
			$("#ddContent").delay(500).slideDown(800);
		}
	);
});

Open in new window

0
 

Author Comment

by:Karl Blackburn
ID: 40289957
Hi,

Apologies, that doesn't seem to work, the idea being as long as you enter or stay within one of the divs the scroll stays down, the div ctl00_ctl10 is onyl wrapped around the wording, when you leave all of them it then waits a couple of seconds and scrolls back up. When I tried this version it went up and down a few times when hovering over the open slider.

Cheers
Karl
0
 
LVL 43

Expert Comment

by:Rob
ID: 40290033
No need to apologise!  I just thought that you wanted the animation to happen when hovering over the words..

So I need to understand exactly what you want to happen when.  So what element do you want to trigger the preview?
0
 

Author Comment

by:Karl Blackburn
ID: 40290126
Basically any element within basketholder and then whilst hovering over the ddcontent area, once you leave any of those completely it should slide back up.
0
 
LVL 43

Accepted Solution

by:
Rob earned 2000 total points
ID: 40290142
Which the following code should do, but what you're showing needs to be in "#basketholder" as well.  What's the element you're showing called?

$(function () {

	var timeout;
	$("#basketholder").hoverIntent(
		function() {
			$("#ddContent").delay(500).slideUp(1200);
		},
		function() {
			$("#ddContent").delay(500).slideDown(800);
		}
	);
});

Open in new window

0
 

Author Comment

by:Karl Blackburn
ID: 40302044
Hi,

Apologies for the delayed reply.

I still havent had much luck using the above, new ideas from me or looking at articles.

The HTML :

<div id="col4" class="col4" style="overflow:visible">
<div id="ctl00_ctl10">
	
<div class="baskettitle"><a id="ctl00_LblBasketTitle" href="basket.aspx">My Basket</a></div>
<div class="basketcontent"><a id="ctl00_LabelBasket" href="basket.aspx">22 items<br>£243.42</a></div>

</div>

<div style="position:relative;height:1px">
<img id="shoppingdot" src="images/siteassets/standard/shoppingbasketbutton.png" style="position:absolute;top:74px; right:80px;z-index:10001" />

<div id="ddContent" class="minibasket">
<div class="minibasketinner"><div class="header">BASKET PREVIEW</div><table style="width:268px; margin-left:6px" cellpadding="4"><tr><td><a href="details.aspx?PID=8205"><img src="http://www.metoyouonline.com/images/product1/G01W1546.jpg" width="60px" /></a></td><td style="text-align:left"><a href="details.aspx?PID=8205">2 x 4" Silver Wedding Anniversary Me to You Bear   <br>Qty : 18</a></td><td>£233.82</td></tr><tr><td style="text-align:center" colspan="3"><img src="images/siteassets/minibasket_break.jpg" /></td></tr><tr><td><a href="details.aspx?PID=9300"><img src="http://www.metoyouonline.com/images/product1/A77TS040.jpg" width="60px" /></a></td><td style="text-align:left"><a href="details.aspx?PID=9300">Wife Anniversary Me to You Bear Card  <br>Qty : 4</a></td><td>£9.60</td></tr><tr><td colspan="3" style="border-top:2px solid #9ed6f5; text-align:right; color:#de006e; font-weight:bold; font-size:13px; padding-top:7px">TOTAL : £243.42</td></tr><tr><td colspan="3"><a href="basket.aspx"><img src="images/siteassets/minibasket_viewbasket.jpg" width="125"></a><img src="images/siteassets/minibasket_button_spacer.jpg" width="6px" height="25px"><a href="basketoffers.aspx"><img src="images/siteassets/minibasket_checkout.jpg" width="125"></a></td></tr></table></div>
</div>

</div>
</div>

Open in new window


I have div col4 wrapping around everything, this holds the basket image slice, total etc and then within this is ddContent, this is a dynamically generated area of the baskets contents.

The issue is using the javascript

$(function () {

    var timeout;
    $(".col4").hoverIntent(function () {
        $("#ddContent").slideDown(200);
        clearTimeout(timeout);
    });

    $("#ddContent").hoverIntent(function () {
        $("#ddContent").slideDown(200);
        clearTimeout(timeout);
    });

    $(".col4,#ddContent").stop().mouseleave(function () {
        timeout = setTimeout(function () {
            $("#ddContent").slideUp(800);
        }, 2000);
    });

Open in new window


or a variety other similiar jquery codes it either

- locks open when i move outside
- goes up and down like a yoyo
- closes when i'm hovering the #ddContent

Any help would be much appreciated?

Cheers
Karl
0
 
LVL 43

Expert Comment

by:Rob
ID: 40305162
Hi Karl,

I'm still missing something.. There's nothing to show as far as I can see...

Why are you wanting the slideDown to happen?  What is shown when this happens?

This is a simplified demo: http://jsbin.com/tagica/1/edit?html,css,js,output

How different do you need it to that?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month16 days, 12 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question