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 8933549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:34:01+00:00 2026-06-15T09:34:01+00:00

I’m working on a responsive site with a specific set of jQuery functions for

  • 0

I’m working on a responsive site with a specific set of jQuery functions for the desktop layout and mobile layout. They interfere with each other if they’re both active at the same time.

By checking window.width, I’m able to deliver only the correct set of functions on page load, and I’d like to do the same on window.resize.

I’ve set up a stripped down Fiddle of where I’m at here: http://jsfiddle.net/b9XEj/

Two problems exist right now:

  1. Either desktopFunctions or mobileFunctions will continuously fire on page resize, whether they have already been loaded or not.
  2. If the window is resized beyond one breakpoint and then returned to the previous size, the incorrect set of functions will already have been loaded, interfering with the current set.

The window.resize function should behave in the following way:

  1. Check if the correct set of functions currently active for the viewport size
  2. If yes, return.
  3. If no, fire correct set of functions and remove incorrect set of functions if they exist.

In the Fiddle example above, you would always see a single line, displaying either “Mobile Functions are active” or “Desktop Functions are active”.

I’m a bit lost at this point, but I have tried using

if ($.isFunction(window.mobileFunctions)) 

to check if functions already exist, but I can’t seem to get it working without breaking the overall function. Here’s a fiddle for that code: http://jsfiddle.net/nA8TB/

Thinking ahead, this attempt also wouldn’t take into account whether the incorrect set of functions exists already. So, I’m really hoping there’s a way I can deal with this in a simpler way and solve both problems.

Any help would be much appreciated!

  • 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-15T09:34:02+00:00Added an answer on June 15, 2026 at 9:34 am

    Following conquers 2 of the problems. The resize fires many times a second, so using a timeout will fix it firing your code constantly. It also adds a check to see if the same size is in effect, and return if it is

    $(document).ready(function() {
    
        var windowType;
        var $wind = $(window);
    
        var desktopFunctions = function() {
            $('body').append('<p>Desktop functions are active</p>');
        }
    
        var mobileFunctions = function() {
            $('body').append('<p>Mobile Functions are active</p>');
        }
    
        var mobileCheck = function() {
            var window_w = $wind.width();
            var currType = window_w < 940 ? 'mobile' :'desktop';
    
            if (windowType == currType) {
                $('body').append('<p>No Type Change, Width= '+window_w+'</p>');
                return;
            } else {
                windowType = currType;
            }
    
            if (windowType == 'mobile') {                
                mobileFunctions();
            } else {
                desktopFunctions();
            }
        }
    
        mobileCheck();
        var resizeTimer;
    
        $wind.resize(function() {
            if (resizeTimer) {
                clearTimeout(resizeTimer);
            }
    
            resizeTimer = setTimeout(mobileCheck, 300)
        });
    
    });
    

    DEMO: http://jsfiddle.net/b9XEj/1/

    Without seeing some real world differences between your 2 sets of functions it is hard to provide gudance on how to stop them conflicting. One possibility is checking the windowType in your functions

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

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.