Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6128689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:39:19+00:00 2026-05-23T16:39:19+00:00

This isn’t a direct question, but more a question on how I can improve

  • 0

This isn’t a direct question, but more a question on how I can improve my javascript by condensing my code and writing in a more logical way.

Basically I just wrote some javascript, using jQuery, in order to create some portfolio animations on my website. You can view the portfolio and animations here:

http://www.saelstrom.com/portfolio/full-portfolio

Everything I wanted to accomplish seems to work. However I just have this feeling that it could have been written with a lot less code. I could be wrong, but I thought I’d put the question out there just in case there’s any experts who’d like to point me in the right direction for the next time I write some javascript.

Here’s my scripts:

$(document).ready(function() {

// ------------------------------------------------------
// - Create jQuery Function - Fade Then Slide Toggle
// ------------------------------------------------------
jQuery.fn.fadeThenSlideToggle = function(speed, callback) {
  if (this.is(":visible")) {
    return this.fadeTo(speed, 0).slideUp(speed, callback);
  } else {
    return this.slideDown(speed).fadeTo(speed, 1, callback);
  }
};

// ------------------------------------------------------
// - Portfolio Item Collapse
// ------------------------------------------------------
$('.folio-item').click(function(){
    collapse = $(this).find('.folio-collapse');
    collapse.slideToggle('slow',function(){
        if($(this).is(':visible')){
            $(this).parent().addClass('open');
        }
        else
        {
            $(this).parent().removeClass('open');
        }
    });
}); 

// ------------------------------------------------------
// - Portfolio Item Hover
// ------------------------------------------------------
$('.folio-item').hover(function(){
    hoveritem = $(this).find('.hover-item');
    hoveritem.fadeIn('fast');
},
function(){
    hoveritem = $(this).find('.hover-item');
    hoveritem.fadeOut('fast');
});

$('.folio-screen').hover(function(){
    hoveritem = $(this).find('.launch');
    hoveritem.fadeIn('fast');
},
function(){
    hoveritem = $(this).find('.launch');
    hoveritem.fadeOut('fast');
});

// ------------------------------------------------------
// - Portfolio Show/Hide Section Wrappers
// ------------------------------------------------------

// - Web Design - Click Function
$('li.port-web').click(function(){

    if($('.web-wrapper').is(':visible')){
        // Do Nothing
    }
    else if($('.marketing-wrapper').is(':visible')){
        // Remove 'active' Class
        $(this).parent().find('li.port-marketing').removeClass('active');
        // Add Class 'active'
        $(this).parent().find('li.port-web').addClass('active');
        // Hide Marketing Wrapper
        $('.marketing-wrapper').fadeThenSlideToggle('slow',function(){
            // Show Web Wrapper
            $('.web-wrapper').fadeThenSlideToggle('slow');
        });
    }
    else if($('.branding-wrapper').is(':visible')){
        // Remove 'active' Class
        $(this).parent().find('li.port-branding').removeClass('active');
        // Add Class 'active'
        $(this).parent().find('li.port-web').addClass('active');
        // Hide Branding Wrapper
        $('.branding-wrapper').fadeThenSlideToggle('slow',function(){
            // Show Web Wrapper
            $('.web-wrapper').fadeThenSlideToggle('slow');
        });
    }
    else if($('.landing-wrapper').is(':visible')){
        // Remove 'active' Class
        $(this).parent().find('li.port-landing').removeClass('active');
        // Add Class 'active'
        $(this).parent().find('li.port-web').addClass('active');
        // Hide Landing Wrapper
        $('.landing-wrapper').fadeThenSlideToggle('slow',function(){
            // Show Web Wrapper
            $('.web-wrapper').fadeThenSlideToggle('slow');
        });
    }

});

// - Internet Marketing - Click Function
$('li.port-marketing').click(function(){

    if($('.marketing-wrapper').is(':visible')){
        // Do Nothing
    }
    else if($('.web-wrapper').is(':visible')){
        // Remove 'active' Class
        $(this).parent().find('li.port-web').removeClass('active');
        // Add Class 'active'
        $(this).parent().find('li.port-marketing').addClass('active');
        // Hide Web Wrapper
        $('.web-wrapper').fadeThenSlideToggle('slow',function(){
            // Show Marketing Wrapper
            $('.marketing-wrapper').fadeThenSlideToggle('slow');
        });
    }
    else if($('.branding-wrapper').is(':visible')){
        // Remove 'active' Class
        $(this).parent().find('li.port-branding').removeClass('active');
        // Add Class 'active'
        $(this).parent().find('li.port-marketing').addClass('active');
        // Hide Branding Wrapper
        $('.branding-wrapper').fadeThenSlideToggle('slow',function(){
            // Show Marketing Wrapper
            $('.marketing-wrapper').fadeThenSlideToggle('slow');
        });
    }
    else if($('.landing-wrapper').is(':visible')){
        // Remove 'active' Class
        $(this).parent().find('li.port-landing').removeClass('active');
        // Add Class 'active'
        $(this).parent().find('li.port-marketing').addClass('active');
        // Hide Landing Wrapper
        $('.landing-wrapper').fadeThenSlideToggle('slow',function(){
            // Show Marketing Wrapper
            $('.marketing-wrapper').fadeThenSlideToggle('slow');
        });
    }

});

// - Branding - Click Function
$('li.port-branding').click(function(){

    if($('.branding-wrapper').is(':visible')){
        // Do Nothing
    }
    else if($('.web-wrapper').is(':visible')){
        // Remove 'active' Class
        $(this).parent().find('li.port-web').removeClass('active');
        // Add Class 'active'
        $(this).parent().find('li.port-branding').addClass('active');
        // Hide Web Wrapper
        $('.web-wrapper').fadeThenSlideToggle('slow',function(){
            // Show Branding Wrapper
            $('.branding-wrapper').fadeThenSlideToggle('slow');
        });
    }
    else if($('.landing-wrapper').is(':visible')){
        // Remove 'active' Class
        $(this).parent().find('li.port-landing').removeClass('active');
        // Add Class 'active'
        $(this).parent().find('li.port-branding').addClass('active');
        // Hide Landing Wrapper
        $('.landing-wrapper').fadeThenSlideToggle('slow',function(){
            // Show Branding Wrapper
            $('.branding-wrapper').fadeThenSlideToggle('slow');
        });
    }
    else if($('.marketing-wrapper').is(':visible')){
        // Remove 'active' Class
        $(this).parent().find('li.port-marketing').removeClass('active');
        // Add Class 'active'
                $(this).parent().find('li.port-branding').addClass('active');
        // Hide Marketing Wrapper
        $('.marketing-wrapper').fadeThenSlideToggle('slow',function(){
            // Show Branding Wrapper
            $('.branding-wrapper').fadeThenSlideToggle('slow');
        });
    }

});

// - Landing Pages - Click Function
$('li.port-landing').click(function(){

    if($('.landing-wrapper').is(':visible')){
        // Do Nothing
    }
    else if($('.web-wrapper').is(':visible')){
        // Remove 'active' Class
        $(this).parent().find('li.port-web').removeClass('active');
        // Add Class 'active'
                $(this).parent().find('li.port-landing').addClass('active');
        // Hide Web Wrapper
        $('.web-wrapper').fadeThenSlideToggle('slow',function(){
            // Show Landing Wrapper
            $('.landing-wrapper').fadeThenSlideToggle('slow');
        });
    }
    else if($('.branding-wrapper').is(':visible')){
        // Remove 'active' Class
        $(this).parent().find('li.port-branding').removeClass('active');
        // Add Class 'active'
                $(this).parent().find('li.port-landing').addClass('active');
        // Hide Branding Wrapper
        $('.branding-wrapper').fadeThenSlideToggle('slow',function(){
            // Show Landing Wrapper
            $('.landing-wrapper').fadeThenSlideToggle('slow');
        });
    }
    else if($('.marketing-wrapper').is(':visible')){
        // Remove 'active' Class
        $(this).parent().find('li.port-marketing').removeClass('active');
        // Add Class 'active'
        $(this).parent().find('li.port-landing').addClass('active');
        // Hide Marketing Wrapper
        $('.marketing-wrapper').fadeThenSlideToggle('slow',function(){
            // Show Landing Wrapper
            $('.landing-wrapper').fadeThenSlideToggle('slow');
        });
    }

});

});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:39:19+00:00Added an answer on May 23, 2026 at 4:39 pm

    For one you could use more chaining:

    // ------------------------------------------------------
    // - Portfolio Item Collapse
    // ------------------------------------------------------
    $('.folio-item').click(function(){
        collapse = $(this).find('.folio-collapse').slideToggle('slow',function(){
            if($(this).is(':visible')){
                $(this).parent().addClass('open');
            }
            else
            {
                $(this).parent().removeClass('open');
            }
        });
    }); 
    
    
    // ------------------------------------------------------
    // - Portfolio Item Hover
    // ------------------------------------------------------
    $('.folio-item').hover(function(){
        hoveritem = $(this).find('.hover-item').fadeIn('fast');
    },
    function(){
        hoveritem = $(this).find('.hover-item').fadeOut('fast');
    });
    
    $('.folio-screen').hover(function(){
        hoveritem = $(this).find('.launch').fadeIn('fast');
    },
    function(){
        hoveritem = $(this).find('.launch').fadeOut('fast');
    });
    

    You could remove redundant code:

    /* ALL THIS CODE CAN GO AWAY */
    
    if($('.marketing-wrapper').is(':visible')){
        // Do Nothing
    }
    
    if($('.web-wrapper').is(':visible')){
        // Do Nothing
    }
    
    if($('.branding-wrapper').is(':visible')){
        // Do Nothing
    }
    
    if($('.landing-wrapper').is(':visible')){
        // Do Nothing
    }
    

    It’s not bad. I’d start there. Your comments take up a lot of space which might give the illusion of verbosity 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This isn't really a programming question but more about programming and testing tools. Is
This isn't that complicated of a question, but I can't wrap my head around
This isn't a question but I thought I'd start a thread where links to
This isn't a very simple question, but hopefully someone has run across it. I
This isn't exactly specifically a programming question (or is it?) but I was wondering:
this isn't really an issue, but more of a concern that I would appreciate
Hopefully this isn't a dupe of another question, but I couldn't see it anywhere
I know this isn't strictly a programming question, but it is related to git.
This isn't a style question. Its more about the proper use of the language
This isn't a programming question but it's about the SDKs and the IDE. I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.