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

  • SEARCH
  • Home
  • 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 9136559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:58:07+00:00 2026-06-17T08:58:07+00:00

I created a little script to handle responsive design for for lower resolution devices

  • 0

I created a little script to handle responsive design for for lower resolution devices and to show a toggle menu instead of a full width menu.
The following script is working fine for me but this looks little bit messy to me. What shorthands or practices should I need to make this code more minimalistic and efficient?

The resetMenu() function is handling to retain CSS for particular resolution while browser resizes from normal mode to toggle mode, is it a good practice to do so?

$(document).ready(function($) {
function resetMenu() {
    $('#top-menu li, #search-form, .social').css({"display":"block"});
    $('#top-menu li').css({"display":"inline-block"});
};
$(window).resize(function () { 
if($(window).width() > 640){
    $(resetMenu());
}
else{
    $('#top-menu li, #search-form, .social').css({"display":"none"}).fadeOut(1000);
    $('#top-menu li:nth-child(2)').css({"display":"none"});
}
});

$(".togglebutton").toggle(
function () {
    if($(window).height() < 360){
        $('#top-menu li').css({"display":"inline-block"}).fadeIn(500);
        $('#top-menu li:nth-child(2)').css({"display":"none"});
        $('#search-form, .social').css({"display":"block"}).fadeIn(500);
        $('#top-menu li').css({"border":"none"});
    }
    else{
        $('#top-menu li, #search-form, .social').css({"display":"block"}).fadeIn(1000);
        $('#top-menu li:nth-child(2)').css({"display":"none"});
    }
},
function () {
    $('#top-menu li, #search-form, .social').css({"display":"none"}).fadeOut(1000);
    $('#top-menu li:nth-child(2)').css({"display":"none"});
}

)});
  • 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-06-17T08:58:08+00:00Added an answer on June 17, 2026 at 8:58 am

    I normally prefer code which has the declaration and execution parts on different modules so, one part would be:

    var one = $('#top-menu li')
    var two = $('#top-menu li, #search-form, .social');
    var three = $('#top-menu li:nth-child(2)');
    var four = $('#search-form, .social')
    
    function toggleIn() {
        if($(window).height() < 360){
            one.css({"display":"inline-block"}).fadeIn(500);
            three.css({"display":"none"});
            four.css({"display":"block"}).fadeIn(500);
            one.css({"border":"none"});
        }
        else{
            two.css({"display":"block"}).fadeIn(1000);
            three.css({"display":"none"});
        }
    },
    
    function toggleOut() {
        two.css({"display":"none"}).fadeOut(1000);
        three.css({"display":"none"});
    }
    
    function resetMenu() {
        one.css({"display":"block"});
        two.css({"display":"inline-block"});
    };
    

    And the other just:

    $(window).resize(function () { 
        if($(window).width() > 640){
            $(resetMenu());
        }
        else{
            two.css({"display":"none"}).fadeOut(1000);
            three.css({"display":"none"});
        }
    });
    
     $(".togglebutton").toggle(toggleIn, toggleOut);
    

    So, how I see it, that second part would be your “minimalistic” code. And each functional part of the code can be separately evaluated, useful for debbugin purposes.

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

Sidebar

Related Questions

I've created a little script for displaying a calendar but the month is 1
I'm a jQuery newbie, and I have trouble with a little script I created.
Hi there Stack Overflow users. I have created a nice little script to append
I created a little script that imports wordpress posts from an xml file: if(isset($_POST['wiki_import_posted']))
Recently started working with pointers and have created a little script that is supposed
I have created a little password generation script. I'm curious to what improvements can
I created a little proxy node script, which looksup the request.url and either passes
I created a little jquery script and I have a problem to use (this)
I need a little help with a script i modified. I've created a submenu
I'm having a little issue running a cron job. I've created this script to

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.