Solved

Open an ul or div with hover on a li,how?

Posted on 2016-11-14
9
52 Views
Last Modified: 2016-11-15
Hello;

I have created a menu bar as you see its,and the codes on this address:

http://jsfiddle.net/jamshidi/6DEv9/173/

Now i want that when hover on an li ,e.g 'Health' then a box open below it which its width be as long as (<div class="navcontainer">) and i could write the submenu for it,so need your help.
Thanks
0
Comment
Question by:MOSTAGHASSI
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 16

Expert Comment

by:SSupreme
ID: 41886780
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 41886812
jQuery :
jQuery(function($) {
	$(".navcontainer ul li").hover(function() {
  	$(".navcontainer_sub").stop().slideDown("fast");
  }, function() {
  	$(".navcontainer_sub").stop().slideUp("fast");
  })
})

Open in new window

CSS :
.navcontainer_sub {
  height: 64px;
  background-color:black;
  display:none;
}

Open in new window

HTMl :
 <div class="navcontainer_sub"></div>

Open in new window

1
 
LVL 82

Expert Comment

by:leakim971
ID: 41886816
0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

Author Comment

by:MOSTAGHASSI
ID: 41886943
Hi leakim971,thanks,this is exactly what i want ,but please let me know that how can keep down the (<div class="navcontainer_sub"></div>) while mouse is over it ,because i will put the submenu inside the div and user must access the links inside div .
0
 

Author Comment

by:MOSTAGHASSI
ID: 41887006
I solved it by adding this jquery to it:

jQuery(function($) {
	$(".navcontainer_sub").hover(function() {
  	$(".navcontainer_sub").stop().slideDown("slow");
  }, function() {
  	$(".navcontainer_sub").stop().slideUp("slow");
  })
})

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 41887025
https://api.jquery.com/hover/
https://api.jquery.com/mouseover/
https://api.jquery.com/mouseout/

jQuery(function($) {
   $(".navcontainer_sub").mouseover(function() {
  	$(".navcontainer_sub").stop().slideDown("slow");
  });
  // here to close when the user click on an element inside navcontainer_sub
  // for example a link : <a hef="/somewhere/somepage.html" class=".menuItem">SOME PAGE</a>
  $(".menuItem", ".navcontainer_sub"), function(evt) {
        evt.preventDefault(); // remove this line if you really want your link redirect the user to the href value
  	$(".navcontainer_sub").stop().slideUp("slow");
  });
})

Open in new window

0
 

Author Comment

by:MOSTAGHASSI
ID: 41887390
thanks,but on line 10 of your last post i have error:

expected an assignment or function call and instead saw an expression
0
 
LVL 82

Expert Comment

by:leakim971
ID: 41887795
there's a typo line 7 :
replace :
$(".menuItem", ".navcontainer_sub"), function(evt) {
by :
$(".menuItem", ".navcontainer_sub").on("click", function(evt) {
0
 
LVL 16

Expert Comment

by:SSupreme
ID: 41888051
I cannot understand how it is better.
ul li ul {display:none; position:absolute; top:45px; left:0; }  
ul li:hover ul{display:block;}

Open in new window

Done. No typos, easy to manage.
Of cause, you can add some fancy staff.
I would use jQuery to add class to an element but not to change inline style, in this case.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
setInterval() calls function twice in one interval 2 50
Execute jQuery after Function 4 37
GitHub 1 34
Disabling a Faux Submit Button 4 35
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

738 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