Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-19-2011, 06:41 PM   PM User | #1
Jenny Dithe
Regular Coder

 
Join Date: Sep 2010
Posts: 457
Thanks: 212
Thanked 1 Time in 1 Post
Jenny Dithe is on a distinguished road
JQuery display none menu loading first as block

Hi,

I have a menu and if you hover over the headings it shows an inline sub menu. The problem I have is that the page loads and for a second shows the full menu with all the subs before hiding the subs and just showing the top navigation headings.

I have tried
.css ('visibility', 'hidden')
$.('.ul').css('visibility', 'hidden')
$('.topnav > li > ul').hide();

I have added and removed visibility:hidden; from the style sheet relating to this ul.

I am completely out of ideas but it looks really messy having everything showing for that second.

Here is my code:
Code:
	$('.topnav > li > ul').css('display', 'none');

	$('.topnav > li').bind('mouseover', openSubMenu);
	$('.topnav > li').bind('mouseout', closeSubMenu);
		
		function openSubMenu(){
			$(this).find('ul').css('display', 'block');
		};

		function closeSubMenu(){
			$(this).find('ul').css('display', 'none');
		};
Jenny Dithe is offline   Reply With Quote
Old 09-19-2011, 06:52 PM   PM User | #2
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
1. you can just use plain old CSS to take care of it

2. you dont need those functions

css:
Code:
.topnav li ul{
display:none;
}
Code:
$(".topnav > li").hover(
  function () {
   $(this).find('ul').toggle;
  }, 
  function () {
    $(this).find('ul').toggle;
  }
);
or maybe,

Code:
$(".topnav > li").hover(
  function () {
   $(this).find('ul').slideToggle;
  }, 
  function () {
    $(this).find('ul').slideToggle;
  }
);
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users

Last edited by DanInMa; 09-19-2011 at 06:56 PM..
DanInMa is offline   Reply With Quote
Users who have thanked DanInMa for this post:
Jenny Dithe (09-20-2011)
Old 09-19-2011, 06:54 PM   PM User | #3
harbingerOTV
Senior Coder

 
Join Date: Jan 2005
Location: Memphis, TN
Posts: 1,765
Thanks: 8
Thanked 123 Times in 121 Posts
harbingerOTV will become famous soon enough
The reason is because the HTML is being written before the JS changes the style. You need to use your style sheet to hide the elements.

edit: yeah, what he said
__________________
Stop making things so hard on yourself.
i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis
harbingerOTV is offline   Reply With Quote
Users who have thanked harbingerOTV for this post:
Jenny Dithe (09-20-2011)
Old 09-20-2011, 10:38 AM   PM User | #4
Jenny Dithe
Regular Coder

 
Join Date: Sep 2010
Posts: 457
Thanks: 212
Thanked 1 Time in 1 Post
Jenny Dithe is on a distinguished road
This is how my style sheet looks:
Code:
.topnav{
	margin:0;
	padding:0;
	}
.topnav li {
	list-style:none;
	float:left;
	font-size:100%;
	width:11.1%;
	}

.topnav li a:link, .topnav li a:visited {
	display:block;
	background-color:#800000;
	text-decoration:none; 
	color:white; 
	}
.topnav li a:hover {
	background-color:#7B68EE; 
	text-decoration:bold;
	}
.topnav li ul {
	visibility:hidden;
	position:absolute;
	z-index:20;
	margin:0;
	padding:0;
	}
.topnav li ul li {
	visibility:hidden;
	display:inline;
	float:none;
	}

.topnav li ul li a:link, .topnav li ul li a:visited{
	visibilty:hidden;
	background-color:#800000;
	text-decoration: none;
	color: white;
	width:auto;
	opacity:0.6;
	filter:alpha(opacity=60);
	}
.topnav li ul li a:hover{
	visibility:hidden;
	background-color:#7B68EE; 
	opacity:0.6;
	filter:alpha(opacity=60);
	text-decoration:bold;
	}
I went for visibility:hidden so that it didn't clash with the display:inline for ul li - I don't know if that is causing the problem, but it is still showing the full menu and sub menu.
Jenny Dithe is offline   Reply With Quote
Old 09-22-2011, 06:54 PM   PM User | #5
Jenny Dithe
Regular Coder

 
Join Date: Sep 2010
Posts: 457
Thanks: 212
Thanked 1 Time in 1 Post
Jenny Dithe is on a distinguished road
Thank you. That worked. I think it was just taking a while for the new style sheet to be read.
Jenny Dithe is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:49 AM.


Advertisement
Log in to turn off these ads.