Tips for positioning a popup in the center of a window

Hello everyone, I'm attempting to integrate a Facebook popup like box into my Blogger blog. However, I am facing an issue where I want the popup to appear in the center of the webpage using absolute positioning. Below is the code that I am currently using. Any help would be greatly appreciated. Thank you.

<style type='text/css'>
#exepopup {
    background-color: none;
    position:absolute;
    z-index: 9999;
    display: none;
    padding: 0px;
    border: 10px solid rgba(82, 82, 82, 0.7);
    -webkit-background-clip: padding-box;
 /* for Safari */
    background-clip: padding-box;
 /* for IE9+, Firefox 4+, Opera, Chrome */
    -webkit-border-radius: 8px 8px 8px 8px;
    -moz-border-radius: 8px 8px 8px 8px;
    border-radius: 8px 8px 8px 8px;
    width: 40%;
    height: 50%;
    overflow: auto;
  /* Recommended in case content is larger than the container */

  margin: auto;
  /* Center the item vertically &amp; horizontally */
  /* Break it out of the regular flow */

  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  /* Set the bounds in which to center it, relative to its parent/container */
}

#exepopup span {
    font-size: 12px !important;
    font-weight: normal !important;
}

#exepopup h1 {
    background: #6d84b4 url(http://4.bp.blogspot.com/-wbOyGFuANTQ/UVF1F4ouC4I/AAAAAAAABiA/RX4jNlICbjM/s1600/aktechz-fb-lock.png) 98% no-repeat;
    border: 1px solid #3b5998 !important;
    color: #FFFFFF !important;
    font-size: 20px !important;
    font-weight: 700 !important;
    padding: 5px !important;
    margin: 0 !important;
    font-family: arial !important;
    overflow: hidden !important;
}

.exepopupdata {
    font-size: 12px !important;
    font-weight: normal !important;
    height: 275px !important;
    padding: 1px !important;
    background: #fff !important;
    border-bottom: 2px solid #ddd;
    overflow: show !important;
}

#exepopupfooter {
    text-align: left;
    font-size:12px;
    background: #F2F2F2 !important;
    height: auto !important;
    padding: 10px 10px 10px 10px !important;
    overflow: hidden !important;
}

#exepopupclose {
    float: right;
    background-color: none !important;
    border: 0px solid #ccc !important;
    color: #111 !important;
    font-weight: normal !important;
    padding: 5px 8px 5px 8px !important;
    text-decoration: none !important;
    display: inline-block !important;
    font-family: arial !important;
    outline: none !important;
    font-size: 12px !important;
    margin: 0px !important;
}

#exepopupclose:active {
    top: 0;
    left: 0;
}</style>
<script type='text/javascript'>
jQuery(document).ready(function() {
function exepopupfunc()  {
var sec = 60
var timer = setInterval(function() {
$("#exepopupfooter span").text(sec--);
if (sec == 0) {
$("#exepopup").fadeOut("slow");
clearInterval(timer);
}
},1000);
var exepopupwindow = jQuery(window).height();
var exepopupdiv = jQuery("#exepopup").height();
var exepopuptop = jQuery(window).scrollTop()+50;
jQuery("#exepopup").css({"top":exepopuptop});}
jQuery(window).fadeIn(exepopupfunc).resize(exepopupfunc)
//alert(jQuery.cookie('sreqshown'));
//var exepopupww = jQuery(window).width();
//var exepopupwww = jQuery("#exepopup").width();
//var exepopupleft = (exepopupww-exepopupwww)/2;
var exepopupleft = 500;
//var exepopupwindow = jQuery(window).height();
//var exepopupdiv = jQuery("#exepopup").height();
//var exepopuptop = (jQuery(window).scrollTop()+exepopupwindow-exepopupdiv) / 2;
jQuery("#exepopup").animate({opacity: "1", left: "0" , left:  exepopupleft}, 0).show();
jQuery("#exepopupclose").click(function() {
jQuery("#exepopup").animate({opacity: "0", left: "-5000000"}, 1000).show();});});
</script>
<div id="exepopup">
<h1>Join Us On Facebook</h1>
<div class="exepopupdata"><center><iframe src="http://facebook.com/plugins/likebox.php?href=https%3A%2F%2Fwww.facebook.com%2FEXEIdeas2010&amp;width=400&amp;colorscheme=light&amp;show_faces=true&amp;border_color=%23fff&amp;stream=false&amp;header=false&amp;height=260" scrolling="no" frameborder="0" style="border:none; overflow:show; width:400px; height:250px;" allowtransparency="true"></iframe></center></div>
<div id="exepopupfooter">Please Wait <span>20</span> Seconds<a href="#" id="exepopupclose" onclick="return false;">Close X</a></div></div>

Answer №1

delete the following CSS properties from #exepopup:

top: 0;
left: 0;

Answer №2

If you want to implement a basic resizing feature, consider using the following code snippet:

function adjustSize(modal) {
  var positionY = $(window).scrollTop();
  var windowHeight = $(window).height();
  var windowWidth = $(window).width();
  modal.css('top', positionY + 20);
  modal.css('left', windowWidth/2 - modal.width()/2);
}

Remember to trigger the above function whenever the browser window is resized:

$(document).ready(function() {
  $(window).resize(function() {
    adjustSize($('#modalContainer'));
  });
});

Answer №3

Check out this live demo on JSFIDDLE:

http://jsfiddle.net/designer12/r4y57v3o/

This example showcases the usage of CSS Style - absolute along with left: 50% to position an element in the middle by utilizing

margin-left:-[half of the element size]

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Styling a Bootstrap dropdown menu so that an input field within it only accepts numeric digits

I am facing an issue with my input field inside a dropdown styled with CSS and I am using Bootstrap 4. When I try to enter characters, it does not work but I can input numbers without any problem. How can I resolve this? <script src="https://cdnjs.cl ...

What steps should I take to adjust the text size in my media query?

I'm facing a challenge with a media query to decrease the font size of a text. It seems like a straightforward task, yet I can't pinpoint the issue. HTML: <div class="fp-featured"> <div class="fp-title">TITLE</div> <p class ...

The issue of jQuery POST methods consistently failing

I have set up a Node.js server using Express with a fairly straightforward configuration: var express = require('express'); var app = express(); app.configure(function() { app.use(express.urlencoded()); app.use(express.json()); app ...

Why is the reference of `this` pointing to `o` in this scenario (o.method)() rather than the global object?

Let's consider the scenario with an object: var o = { prop: 3, method: function() {return this.prop} } My expectation was that calling (o.method)() would result in undefined, but instead it returned 3, indicating that the reference of this ...

Can @keyframes be iterated through CSS (particularly Stylus)?

Here is some Stylus code I'm working with: for i in (1..3) .l:nth-child({i}) opacity (i / 5) When executed, the output looks like this: .l:nth-child(1) { opacity: 0.2; } .l:nth-child(2) { opacity: 0.4; } .l:nth-child(3) { opacity: 0.6; } ...

Prevent D3.js from constantly refreshing

I am encountering an issue with my AngularJS web app where multiple D3 line graphs are constantly redrawing, even when the underlying data remains unchanged. I am looking for a way to prevent or minimize these unnecessary redraw events. What is perplexing ...

Initiating a GET request to retrieve the file generated by the server

I am currently delving into the Mean stack and have encountered a challenge with downloading a file from my server-side application using the Angular front end. Despite successfully generating the file on the back end, clicking the download button on the f ...

Press the Enter key to submit

Encountering issues while trying to enter an event. Despite reviewing several posts on this matter, a solution has not been found yet. The project needs to function properly in Chrome, FF & IE (8,9,10,11), but it is currently not working on any browser. T ...

Utilizing Vue to create multiple components and interact with Vuex state properties

I am currently learning Vue and using it with Vuex (without Webpack). However, I am facing some challenges while implementing a simple example and the documentation is not very clear to me. One issue I encountered is that I cannot access the Vuex st ...

NodeJS: A guide to sending a ZAP post request

I have a unique URL similar to this: https://hooks.zapier.com/hooks/catch/2020200/jasoa43 I am trying to determine my code, figure out how to retrieve the port, and establish the correct path. Here is the code snippet for reference, could you please assis ...

How to assign a value to an array within a form in Angular 8

I'm facing an issue with my Angular 8 edit form that utilizes a form array. When I navigate to the page, the form array is not populated with values as expected. Can anyone help me identify and solve this problem? ngOnInit(): void { // Fetc ...

Node is throwing a 302 error on Localhost:3000

Looking for some guidance as a beginner trying to create and run a nodejs application. Encountering an error while running server.js via nodemon, the console displays the following: Express server listening on port 3000 Mongoose default connection open t ...

Increasing the checkout date by one day: A step-by-step guide

I am looking to extend the checkout period by adding 1 more day, ensuring that the end date is always greater than the start date. Below are my custom codes for implementing the bootstrap datepicker: $(function() { $('#datetimepicker1').da ...

Converting a date string into an Excel date type when exporting JSON data in JavaScript

I am dealing with JSON objects that have dynamic properties and need to export them to Excel using JavaScript in a way that Excel recognizes date strings (e.g., 2020-03-13) as date objects. However, when I use the xlsx library to download the Excel file, t ...

ThreeJs is known for effortlessly handling an abundance of vertices, far surpassing the number typically found

I came across this code snippet: function loadObject(filePath){ var loader = new THREE.OBJLoader(); loader.load( filePath, function ( object ) { child = object.children[0]; var geometry = new THREE.Geometry().fromBufferGeometry( ch ...

The browser automatically adds a backslash escape character to a JavaScript object

When attempting to send an MQTT message to a topic from my angular app, the message needs to be in a specific syntax: { "Message": "hello" //the space after : is mandatory } However, upon sending the message in the correct format, the browser aut ...

Utilizing ExtJS and its control feature

I am facing an issue with the following code block: run: function(e, row){ var me = this; var container = Ext.getCmp('centercontainer'); try { container.removeAll(); } catch(e) { } // The code snippet below is act ...

Creating interactive network visualizations using JavaScript

I've been in search of javascript code that can help me create a visual representation similar to this example. Specifically, I need something that can display links between boxes when clicked on or hovered over. I'm still not sure what this par ...

Issues arising while passing a parameter to a Node.js module

I've been struggling with passing a variable to a module. In my node.js setup, I have the following structure: The main node.js server (server.js): // modules ================================================= var express = require('expr ...

Unable to stop interval in Angular 5 application

My setInterval() function seems to be working fine as the timer starts, but I am encountering an issue with clearInterval(). It does not stop the timer when the counter value reaches 100 and continues running continuously. Any help or suggestions would be ...