Web Design Forum  
 
Go Back   Web Design Forum > Web Software > Scripts

Reply
 
LinkBack Thread Tools Display Modes
Old 09-25-2011, 09:56 AM   #1
New Member
 
Join Date: Aug 2011
Location: Staffordshire
Posts: 3
Question Jquery if & else statement for visible and hidden

Hey all,

I'm working on a summer project for university, and I am 99% finished on it, there is just one small thing that I am stuck on;

I have a navigation system with a sub menu within one of the anchors, the sub menu has fadeIn on it when you click on the anchor, and so what I am after is;

When the sub menu is visible, I need the homepage opacity to drop to 25%, and when the sub menu is hidden I need the homepage opacity to come back to 100%

I thought this was possible through an If, else statement but as I am a novice I am unsure of this, and so far got this;

Code:
$("#cat").click(function(){
 if ($('.sub1').is(':visible') ) {
 $(".homepage").fadeTo(500, .25);}

 else {
 $(".homepage").fadeTo(500, 1);

 }

I have also tried this via .CSS which partially works, when the sub menu is visible the Homepage opacity drops but then when I click #cat and the sub menu is hidden, the homepage won't come back to 100% opacity ;

Code:
$("#cat").click(function(){
    if ($('.sub1').css('opacity') == .25 ) {  

        $('.homepage').fadeTo(500, 1);

    } else {

        $('.homepage').fadeTo(500, .25); 
    }
});
Djsquid is offline   Reply With Quote


Old 09-26-2011, 03:14 PM   #2
Silver Member
 
Join Date: Jul 2011
Posts: 146
Default

Could this help: http://api.jquery.com/toggle-event/
DesignerBill is offline   Reply With Quote
Old 09-28-2011, 06:18 AM   #3
New Member
 
Join Date: Sep 2011
Posts: 5
Default

Quote:
Originally Posted by DesignerBill View Post
might help, I suggest w3school
__________________
Non-profit Website
Krocker360 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:42 PM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.