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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:29:29+00:00 2026-06-02T03:29:29+00:00

So what i want. There will be some content centered on a page (horizontally

  • 0

So what i want.

There will be some content centered on a page (horizontally & vertically).
The user will be able to click to load the previous/next bit of content.
This content will load dynamically with Ajax.

When

everything will happen in reverse for the Next>

To center the content i am using jQuery as i will not know the content size.

heres the code i am using:

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

$("div.item1").center(true);

To make sure it centers when the browser resizes i’m using :

$(window).bind('resize', function() {
    var that = this;

    if (!('balancer' in that)) {
        that.balancer = setTimeout(function() {
            $("div.item1").center(true);           
            delete that.balancer;
        }, 200);
    }
});

I’ve attempted to use this code to do the animations required. So far no luck.
item1 appears how i want it to but not quite in the right place (the left: -=100 putting it off)

$('.item1').animate({
    opacity: 1,
    left: '-=100'
}, 1000);

$('.item2').animate({
    opacity: 1,
    left: '+=100'
}, 1000);

Ive set up a jsfiddle here to show where i’m at:

http://jsfiddle.net/GmRJ9/

I’m not too hot on my jQuery in general so go easy on me but i feel it’s not too complicated.

However the fact that i want to use it with dynamically loading items might cause some problems. So with that in mind I should probably ask if i’m approaching this in the right manner?

Any guidance would be much appreciated!
thanks in advance,

J

  • 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-02T03:29:31+00:00Added an answer on June 2, 2026 at 3:29 am

    Struggling first I was doubting the formulae for the middle. But maken the container an rectangle (change height!) you see it’s working.
    Also you see, when taking away the margin for item1, that the position behaves the same for both items.

    So assuming the JS is fine I thought maybe some CSS error. Some hidden margin or padding but setting both to zero revealed nothing.

    After Swapping browser for developer tools I repeated the steps and realised the items seemed to be placed relative to the container.

    <div class="container"></div>
    <div class="item1">
        <p>item1</p>
    </div>
    <div class="item2">
        <p>item2</p>
    </div>
    

    Bingo!

    Here is an example spiced up with a 2 seconds delay. I always struggle to set the timeout right. Might be nice to see it =) http://jsfiddle.net/3xLAD/
    Strangely I couldn’t set the items’ margin-top via CSS. This made the div move slightly horizontal (ò.O)-> http://jsfiddle.net/9ydrQ/

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

Sidebar

Related Questions

I want to make a webapplication in witch there will be some users with
I have a page where there will be many tabs and i want to
So I have some user generated content areas of my site. I want them
I want to create some kind of simulation. There will be numerous sprites floating
By default for creating content a new page is opened. I want to do
I want to create a page which has footer and some common parts. On
i want a background image that is larger than the content, which will remain
Is there an option to block some content in web browser without ID of
I have an article list page. It needs to show some content information about
I'm writing a game that will have a lot of information (configuration, some content,

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.