Photoshop Contest PhotoshopContest.com
Creative Contests. Real Prizes. Essential Resource.
You are not logged in. Log in or Register

 


Photoshop Contest Forum Index - Ask the Experts - jQuery gurus? - Reply to topic

TofuTheGreat

Location: Back where I belong.

Post Mon Mar 15, 2010 12:14 pm   Reply with quote         


I've got a site with a jQuery "mega menu".

Right now the menu sub flows outside the layout (as shown below). This is a problem if the available chrome isn't wide enough to see the menu.



What I want it to do instead:



I need to come up with a jQuery function that detects the width of the drop-down, checks to see if that width is larger than the remaining amount to space to the right. If it is then move the menu to the left instead of the right.

I'm just new to jQuery so I'm a bit lost. Confused




_________________
Why I do believe it's pants-less o'clock! - Lar deSouza
”The mind is like a parachute, it doesn’t work if it isn’t open.” - Frank Zappa
Created using photoshop and absolutely no talent. - reyrey

Michel

Location: Montreal, Canada

Post Mon Mar 15, 2010 4:58 pm   Reply with quote         


TofuTheGreat wrote:
I need to come up with a jQuery function that detects the width of the drop-down, checks to see if that width is larger than the remaining amount to space to the right. If it is then move the menu to the left instead of the right.

I'm just new to jQuery so I'm a bit lost. Confused


I don't know if there's a fonction that is prepackaged in jquery that you can call upon. I know you could write something in java, but I would be of no help in that field. Why don't you try sticking a "class" on that <ul> that is in the far right and move it with css?




jazpur

Location: Italy

Post Tue Mar 16, 2010 8:21 am   Reply with quote         


Maybe you can put a container div around the menu to force sub items to stay inside the container (not sure if it will work)

a rough sketch of the script:

//max width
var maxWidth = 800;
//Width of menu
var menuWidth = $("#topnav").width();

var spaceAvailable = maxWidth - menuWidth;

//Get width of last submenu, (ul of last li)
var lastSubWidth = $("#topnav ul li:last lu").width()

//Get width of last li
var lastLiWidth = $("#topnav ul li:last").width()

if(lastSubWidth -lastLiWidth > spaceAvailable)
{
var spaceToLeft = lastSubWidth - lastLiWidth ;

//Postition last ul more to the left with negative value;
$("#topnav ul li:last lu").css("left", 0 - spaceToLeft);
}

I assume maxWith is known because it's the container of the menu. Just a rough sketch, needs debugging testing etc.

Nice menu ! I will try it when i have time.
I hope this helps you in the right direction.




_________________

TofuTheGreat

Location: Back where I belong.

Post Wed Mar 17, 2010 1:54 pm   Reply with quote         


Thanks to jazpur's help and hints I got it!

Code:
       
       //reposition if the sub slides off screen
        var subMenu = $(this);
        var subPosition = subMenu.position();
        var subLeft = parseInt(subPosition.left);
        var subWidth = rowWidth;
        var subRight = subLeft + subWidth;
        var newLeft = 0;

        if (subRight >= document.documentElement.clientWidth){
          newLeft = document.documentElement.clientWidth - subRight - 40; //scrollbar width cushion
          $(this).find(".sub").css({'left':newLeft});
        }




_________________
Why I do believe it's pants-less o'clock! - Lar deSouza
”The mind is like a parachute, it doesn’t work if it isn’t open.” - Frank Zappa
Created using photoshop and absolutely no talent. - reyrey

Photoshop Contest Forum Index - Ask the Experts - jQuery gurus? - Reply to topic

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Navigate PSC
Contests open  completed  winners  prizes  events  rules  rss 
Galleries votes  authentic  skillful  funny  creative  theme  winners 
Interact register  log in/out  forum  chat  user lookup  contact 
Stats monthly leaders  hall of fame  record holders 
PSC advantage  news (rss)  faq  about  links  contact  home 
Help faq  search  new users  tutorials  contact  password 

Adobe, the Adobe logo, Adobe Photoshop, Creative Suite and Illustrator are registered trademarks of Adobe Systems Incorporated.
Text and images copyright © 2000-2006 Photoshop Contest. All rights reserved.
A venture of ExpertRating.com