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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:50:30+00:00 2026-06-15T22:50:30+00:00

How to centre the div on the website? ive such script: $(document).ready( function(){ $(‘.cod’).click(function()

  • 0

How to centre the div on the website? ive such script:

$(document).ready( function(){    

    $('.cod').click(function() {
    var div_name = $(this).attr('id');

    $('#overlay_window').load('/templates/' + div_name + '_template.php', function(){
    var div_width = $('#'+div_name+'-overlay').width();
    var div_height = $('#'+div_name+'-overlay').height();
    $('#overlay_window').css("width", ""+div_width+"px")
    $('#overlay_window').css("height", ""+div_height+"px")
    var div2_width = $('#overlay_window').width();
    var div2_height = $('#overlay_window').height();
    var window_width = $(window).width();
    var window_height = $(window).height();

    var widthoffset = (window_width - div2_width) / 2;  
    var heightoffset = (window_height - div2_height) / 2;   
    $('#overlay_window').css("left", "" + (widthoffset) + "px");
    $('#overlay_window').css("top", "" + (heightoffset + 750) + "px");
    $('#overlay_background').fadeIn(800);
    $('#overlay_window').fadeIn(800);
    });
    });




    });

but it centres the div from top of page and if its scrolled down it appears on top not there where ive scrolled, can someone help?

  • 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-15T22:50:31+00:00Added an answer on June 15, 2026 at 10:50 pm

    Why not just mark it position: fixed and keep it there regardless of where the user scrolls? Then you don’t need any form of js trickery.

    However, to answer your current problem, it seems you provide the centering once, you you never react to the scroll event of the window:

     $(window).scroll(function() { $('#divID').center(); });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use a div to centre a website, should this be done
I'm trying to centre multiple div elements on a page. Some however need to
I am having a div, which should be centre of the window, even after
I want to center a div in the document body in jquery. I have
I've made a website where on the main div, multiple div's are displayed (
There are spaces rendered between <div> s as shown on this website . I've
Basically I'm laying out a website and I'm using DIV's to have a header,
I have a website that, upon clicking a link generates a div. Allow me
Possible Duplicate: How to center div horizontally and vertically I need to put image
How can I get the center div to exactly center to the parent div.

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.