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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:46:13+00:00 2026-05-28T01:46:13+00:00

With the following function I center an object in the window if the user

  • 0

With the following function I center an object in the window if the user chooses so :

var showObj = function(obj) {

    setTimeout(function () {
        if(opts.centerObj == true) {
            var cssProps = {
                'position' :'absolute',
                'top' : (($(window).height() - $(obj).outerHeight()) / 2)+'px',
                'left' : (($(window).width() - $(obj).outerWidth()) / 2)+'px'
            }
            obj.css(cssProps).fadeIn('slow');
        }
            else {
                obj.fadeIn('slow');
            }
    }, 1500);

}

But I want to tweak this function or make another one which would center the object if the window resizes.

I’ve seen I can use this :

$(window).resize(function() {
   obj.css(cssProps);
});

But I think I’m wrong,because nothing happens when I resize the window.

So could someone show me how to create that function that does what I need or tweak the current function so it does that ?

  • 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-28T01:46:14+00:00Added an answer on May 28, 2026 at 1:46 am

    That depends on where you are calling cssProps. Since it’s inside a private function it’s not accessible unless you tell it to be. I think the easiest way to do what you want is to pull out the bit of code that creates the JS object and put it into it’s own function.

    var showObj = function(obj) {
    
        setTimeout(function () {
            if(opts.centerObj == true) {
                var cssProps = getProps(obj);
                obj.css(cssProps).fadeIn('slow');
            }
            else {
                obj.fadeIn('slow');
            }
        }, 1500);
    
    }
    
    var getProps = function(obj) {
    
        return {
            'position' :'absolute',
            'top' : (($(window).height() - $(obj).outerHeight()) / 2)+'px',
            'left' : (($(window).width() - $(obj).outerWidth()) / 2)+'px'
        }
    }
    
    $(window).resize(function() {
        var cssProps = getProps(obj);
        obj.css(cssProps);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function: void CGlEngineFunctions::GetBezierOpposite( const POINTFLOAT &a,const POINTFLOAT &center, POINTFLOAT &b,
I have the following function: simpleModal: function (data, id) { var responseHtml = data;
The following sample code provided by google maps api var geocoder; var map; function
The following function System.Threading.Thread.Sleep(); delay the thread in millisecond, and take the integer value
/** The following function checks the red black tree black height * @param n
The following function generates a 'stack level too deep (SystemStackError)' for n = 5,000
The following function is trying to find the nth to last element of a
/************************************************************************** * * Function: toggleVis * * Description: Following Function hides and expands the
I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)
I have the following function that is pulling data from a database. The ajax

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.