JavaScript and Responsive Design Techniques

I'm struggling to create a responsive page that starts with a mobile-first approach, but I keep running into the same issue.

When I have my dropdown menu in the mobile version, it looks good. However, when I try to switch it to the non-mobile version, it doesn't work. I want a mobile version with one column and then switch to two columns when the window size exceeds 400px.

After numerous changes, this is what my current code looks like:

$('.slide ul').slideUp();

var windowSize;
windowSize = $('.wrapper').width();
$(window).on('load', checkSize());

$(window).resize(checkSize());


function checkSize(e) {
    if (windowSize < 400) {
        mobile();     
    } else if (windowSize > 400) {
        noMobile();
    }
}


function mobile(e){
    $('.especial').hide();      
    $('.toggle').on('click', toggleMenu);  

}

function toggleMenu(e){
    $('.slide ul').slideToggle();
    e.preventDefault(); 
}

function noMobile(e){
    $('.lista').show();

    var selectedList;
    selectedList = $('.elegidos').html();
    $('.especial').prepend(selectedList);     
}

Thank you for your help!

Answer №1

One way to handle this is utilizing CSS media queries:

@media (max-width: 400px) {
  .list {
    display: block;
  }
  .special {
    display: none;
  }
}

@media (min-width: 401px) {
  .list {
    display: none;
  }
  .special {
    display: block;
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Running Selenium tests are not able to initiate Javascript ajax requests

I'm currently troubleshooting a scenario using Selenium that involves the following steps: - When a user inputs text into a textarea, an ajax request is sent, which then adds the text to the database (implemented using django and processed in view.py) ...

Data retrieval is currently not functioning, as React is not displaying any error messages

One of the components in my app is as follows: import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { compose } from 'redux'; import { translate ...

Issues with CSS Modules not applying styles in next.js 13 version

Employing next.js 13.1.1 along with /app Previously, I had been handling all of my styles using a global.css, however, I am now attempting to transition them into CSS Modules. Within my root layout.js, there is a Header component that is imported from ./ ...

Is it possible to send a search query to thesaurus.com using HTML code on a webpage?

I've created an HTML page with a text field and a submit button. When the user enters a word in the text field and clicks submit, a servlet fetches the input using request.getParameter(). Now, I need assistance implementing functionality to send this ...

The rationale behind organizing analogous variables into groups

Currently, I am grappling with determining the optimal logic for grouping parameters within a specified tolerance level. Let me illustrate this with an example... Task1: parameter1=140 Task2: parameter1=137 Task3: parameter1=142 Task4: parameter1=139 Task ...

The variable in the dataTables JavaScript is not receiving the latest updates

//update function $('#dataTable tbody').on('click', '.am-text-secondary', function() { //extract id from selected row var rowData = table.row($(this).parents('tr')).data(); var updateId = rowData.id; ...

What is the process for retrieving User Information using AngularJS following NodeJS authentication?

While I've come across similar questions on this topic, my lack of experience with Angular and Node is making it difficult for me to find a suitable solution. I had previously written this code that successfully handled the login process and allowed ...

What is the best way to halt the execution of content scripts in the active tab?

I am currently developing a Google Chrome Extension and have come across a bug that I am struggling to fix on my own. The extension works as intended when switching to Youtube's Dark Mode on a single tab. However, if you are on Youtube and open a new ...

Several pictures are not displaying in the viewpage

I have a controller method set up to fetch files from a specific folder. public JsonResult filesinfolder(ProductEdit model) { string productid = "01"; string salesFTPPath = "C:/Users/user/Documents/Visual Studio 2015/Projects/root ...

A guide on installing a npm dependency module from a local registry domain

I have successfully published a module on my own custom registry domain, located at , and I am able to publish updates to the module there. Unfortunately, I am encountering an issue with dependencies within my published module. For example: "dependencies" ...

Encountering excessive re-renders while using MUI and styled components

Hey there! I recently worked on a project where I used MUI (Material-UI) and styled-components to render a webpage. To ensure responsiveness, I made use of the useTheme and useMediaQuery hooks in my web application. My goal was to adjust the font size for ...

What is the best way to position the left sidebar on top of the other components and shift them to the

Currently, I am working on a project to display NBA data fetched from an API. I am aiming to recreate the design showcased here: Dribbble Design My main challenge lies in overlaying the left sidebar onto the main box and shifting the components sligh ...

Problem with loading messages in VueI18n locale

Utilizing the vueI18n package for language localization in our application, we fetch the locale messages object via an api call. Within our config file, we have specified the default language which is used to load the locale before the creation of app.vue. ...

Having difficulty finding the close button in a pop-up window while using the Selenium library with Python

While using chromedriver to open the website mentioned below in my extract_data() function, I encountered a problem with dismissing a pop-up message by clicking the 'x' button. Surprisingly, it seems to click the wrong button instead. What' ...

MVC.NET: Offering User-Friendly Loading of Initial x Items with an Option to Load More

What would be the optimal approach to efficiently load only the initial 25 elements from an IEnumerable within an ASP.NET MVC Index view? Upon employing scaffolding, a controller and views have been constructed. Within the index page, there is a creation ...

Javascript Developer Platform glitches

Describing this issue is proving difficult, and I have been unable to find any solutions online. My knowledge of Javascript and its technologies is still quite new. I am currently working on a web application using NodeJS, Express, and Jade that was assig ...

The switch/case function I implemented is functioning correctly, however, an error is being displayed in the console stating "Cannot read property 'name' of null"

Check out the live codepen demo here After selecting "elephant" from the third dropdown, the console.log(brand.name) displays "elephant" as expected and executes the rest of the switch statement successfully. However, there seems to be a console error oc ...

Interface key error caused by the TypeScript template literal

Version 4.4.3 of Typescript Demo Playground Example -- interface IDocument { [added_: `added_${string}`]: number[] | undefined; } const id = 'id'; const document: IDocument = { [`added_${id}`]: [1970] } My Attempts: I made sure that id in ...

Storing user input from a dynamic form into a database using Kendo UI

I've successfully populated dynamic input form fields. However, I'm unsure how to save the data into a database using a put/post API since I have only used a get API so far. HTML code <div id="renderform" class="form horizontal-for ...

Unfolding the potential of variables in JSON.stringify with Node.js

I am currently developing a node.js API for my app, which includes a simple TCP server that accepts NDJSON (newline delimited JSON). However, I have encountered an issue with the JSON stringify method. The problem arises when I attempt to expand all variab ...