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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:33:26+00:00 2026-06-01T13:33:26+00:00

So I have a piece of code: jQuery.fn.center = function(parent) { parent = this.parent();

  • 0

So I have a piece of code:

jQuery.fn.center = function(parent) {
parent = this.parent();
this.css({
"position": "absolute",
"top": ((($(parent).height() - this.outerHeight()) / 2) + $(parent).scrollTop() + "px"),
"left": ((($(parent).width() - this.outerWidth()) / 2) + $(parent).scrollLeft() + "px")
});
return this;
}

This code grabs an element and moves it to the center of the parent. Works nicely. There are a couple of things I would like it to do aside of what it’s doing.

  1. I need it to float above all other elements in that parent. A z index more or less. I tried to apply a z-index, but it didn’t seem to work. I dunno if I may have been doing it wrong, or if there is a better way.

  2. I need it to move back to the position it was in. The way this works, is the block is gonna be positioned on the page (via CSS), and when the user clicks, it moves it to the center of the page, as the code is already doing. Is there any way that, if a user clicks an exit button, I can program said button to move it back to where it originally was? i don’t know if I can pass variables around in jQuery.

  3. This option is more for aesthetics, and i don’t deem it necessary, but would like it if you have a little extra time. I would like the block to slide from it’s position to the center of the page, and back, as opposed to just popping there. As I stated, this is just aesthetics and i really don’t need that to happen.

Much appreciated to anyone that can help me out.

  • 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-01T13:33:28+00:00Added an answer on June 1, 2026 at 1:33 pm

    I tried to implement a similar requirement but It should have all the features that you were looking for. Try DEMO

    I need it to float above all other elements in that parent. A z index
    more or less. I tried to apply a z-index, but it didn’t seem to work.
    I dunno if I may have been doing it wrong, or if there is a better
    way.

    I always use z-index in range of 1001 or greater for such cases. Even in the demo, it works fine. Try this and let us know if you still not working for you.

    I need it to move back to the position it was in. The way this works,
    is the block is gonna be positioned on the page (via CSS), and when
    the user clicks, it moves it to the center of the page, as the code is
    already doing. Is there any way that, if a user clicks an exit button,
    I can program said button to move it back to where it originally was?
    i don’t know if I can pass variables around in jQuery.

    I stored the original position of the element using .data API and restored it back to its original position when close(exit) button is clicked.

    This option is more for aesthetics, and i don’t deem it necessary, but
    would like it if you have a little extra time. I would like the block
    to slide from it’s position to the center of the page, and back, as
    opposed to just popping there. As I stated, this is just aesthetics
    and i really don’t need that to happen.

    You can use .animate instead of CSS which will transcend the element from it original position to the destination position in specified time.

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

Sidebar

Related Questions

I have the following piece of code: jQuery.fn.shake = function(intShakes, intDistance, intDuration) { this.each(function()
I have this simple piece of code in jQuery $(document).ready(function() { $('#switcher').click(function(event) { if
Hey guys, I have this piece of jquery code: <script type=text/javascript > $(function() {
I have this piece of code written in jQuery and PHP: <script type=text/javascript> $(document).ready(function(){
I have the following piece of code: if((String(parent).length > 0) && (String(this.className).length > 0))
I have this piece of Jquery code that grabs a heading in a table
I have an application that executes this piece of code (JQuery 1.4.2) in an
I have this piece of code: $(#faq).click(function () { var url = $.get(faq, {
I have this JQuery piece of code. I want to see wht php outputs.
I have this little piece of jQuery/jqModal code which works fine. However, I am

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.