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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:09:28+00:00 2026-06-18T09:09:28+00:00

I have this js code: $(window).resize(function() { var formHeight = $(.box-demo).outerHeight() + 40; $(.box-demo).css(top,-formHeight+px);

  • 0

I have this js code:

$(window).resize(function() {
    var formHeight = $(".box-demo").outerHeight() + 40;
    $(".box-demo").css("top",-formHeight+"px");
});

When you resize the window. The box-demo is recalculating the height of the form. But now i have a problem with this on mobile devices.

Only when the change width. Then this function must be performed. Now it happened when the document changing the height and width. How can i make this. That is only performed when i changed the width of the document.

Thanks for helping!

  • 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-18T09:09:29+00:00Added an answer on June 18, 2026 at 9:09 am

    There’s possibly a better way of doing this, but you could base it on a preset window width value. Only if the width changes should the resizing occur:

    var windowWidth;
    
    $(document).ready(function() {
        windowWidth = $(window).width();
    })
    
    $(window).resize(function() { 
        if($(this).width() != windowWidth)
        {
            var formHeight = $(".box-demo").outerHeight() + 40;
            $(".box-demo").css("top",-formHeight+"px");
            windowWidth = $(this).width();
        }
    });
    

    Edit: You can also avoid having to append the “px” by using:

    $(".box-demo").css({top: -formHeight});
    

    Edit 2: If you want to make it change when only the width has changed, you could also add a height check as well:

    var windowHeight;
    ...
    if($(this).width() != windowWidth && $(this).height) == windowHeight)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: function c() { var h = ($(window).height() - $('#maincontainer').outerHeight())
I have this code: function viewport() { var height = $(window).height(); viewport = parseInt(height)
I have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
I have code like this: $(document).ready(function() { $(div #covert, div #coverb).height($(window).height() / 2 +
I have this code inside a iframe: window.addEventListener('message', function(e){ if(e.data == 'test') console.log(e); },
I have this form submit code: Event.observe(window, 'load', init, false); function init() { Event.observe('addressForm',
I have some html5 postMessage code: window.addEventListener(message, FA.recieveMessage, false); That listener invokes this function:
I have a jQuery flot chart with this code: $(table.statics).each(function() { var colors =
I have this piece of code that calculate height for an element: //resize bar
I have this code: public class Window extends JFrame { public Window(){ ... JButton

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.