Centering A Div
Nov 22, 2005
I have a bit of code that unhides a div and then loads an image into it.
What I would really like is to have that div center on the users screen.
How do I go about doing that?
function unHide(ImgSrc) {
var newsrc = document.getElementById('enlargedImg');
var newWin = document.getElementById('divOpen').style.visibility = 'visible'
newsrc.src = ImgSrc;
}
View 3 Replies
ADVERTISEMENT
Mar 10, 2001
How do you center the a pop-up window on the screen after a mouseclick on a button?
View 9 Replies
View Related
Jul 23, 2005
I'd like to append/amend the following code from the Dreamweaver extension "Open Picture Window Fever" for the ability to center the PopUp window:
By default, it allows the window to be offset on the left and top, but does not include a centering option.
I'm thinking it would include something like (screen.width-imageWidth)/2;
somewhere but not sure how do go about doing this.....
View 17 Replies
View Related
Nov 24, 2011
I have a large image which is centred horizontally and is 300px from the top of the web page. I have some code which will shrink the image, but am struggling to know how to ensure that the image remains centred as it shrinks, and also moves to the top of the page. Can anyone point me in the right direction? The code I have so far is...
Code:
window.onload = function(){
$("#logo").animate({width: "-=400", height: "-=200"}, 5000);
};
View 1 Replies
View Related
Jan 3, 2010
ive been strugglng all day to centre a DIV with javascript in the centre of my page. Ive created a modal popup and id like it to stay in the screen even if the page has been scrolled down. And no matter what i try i cant get it to actually hit the centre of the screen. I should add that im totally new to javascript but decided i cant avoid learning javascript forever so here are my pathetic efforts..
function ShowPopup(hoveritem, thepopup, theimage)
{
popVar = document.getElementById(thepopup);
[code]....
Ive tried loads of other things too, whats commented out has been my last effort. Im doing other things too in the function in case you wondered.
View 6 Replies
View Related
Jul 23, 2005
I have the following funciton that centers my website content for any size window and will center it in real time as the window is expanded or shrunk. It is activated by a
onresize="CenterIt();"
in the body tag.
Works fine for IE. How do I make it compatible with netscape and most browsers? Better yet, is there a good single source that explains how to write javascript to be compatible with all browsers? 766 and 435 are the width and height of my table that surrounds the website data defined so:
<TABLE id="Main" style="position:absolute; z-index:0; top:0; left:0;">
function CenterIt()
{
newOffsetWidth = 0;
newOffsetHeight = 0;
if (document.getElementById)
{
winW = document.body.offsetWidth;
winH = document.body.offsetHeight;
}
else if (document.all)
{
/*
What goes here????
*/
}
else if (document.layers)
{
/*
What goes here????
*/
}
if (winW > 766)
newOffsetWidth = ((winW - 766) / 2) - 10;
if (winH > 435)
newOffsetHeight = ((winH - 435) / 2);
if (document.getElementById)
{
document.getElementById('Main').style.left = newOffsetWidth;
document.getElementById('Main').style.top = newOffsetHeight;
}
else if (document.all)
{
/*
What goes here????
*/
}
else if (document.layers)
{
/*
What goes here????
*/
}
}
CenterIt();
View 6 Replies
View Related
Mar 21, 2010
I have 50 thumbnails running vertically down the page, so that the viewer must scroll quite a bit to see them all. When a thumbnail is clicked I want to display the full size image in the middle of the viewport. Thus, the top offset of the absolute div that displays the full size picture will change depending on how far down the viewer has scrolled.
I can bind a function to the <img> tag that will set the top offset of the div where the full size images are displayed but I don't know how to get the current position of the viewport, or how to position something with respect to the viewport.
Can jQuery pull the viewport position out of the DOM and let me center something in it?
View 3 Replies
View Related
Sep 18, 2009
A client has a 1440 wide flash move in .swf format that serves as in intro to the site. They want the flash movie centered on the screen even if the resolution is lower, at 1024 or whatever. At this point my idea is to wrap the flash object in a div and center that div using javascript so that it centers no matter the screen width, but I don't know exactly how to do this.
View 7 Replies
View Related
Feb 16, 2011
I'm creating a Dreamweaver CSS site based off a template I purchased.In this site,I want to have page with a gallery of my company's products.So I went to http://smoothgallery.jondesign.net/, used the "Gallery Set" setup, and put it into my web page.It all works GREAT...except the gallery is left-aligned and I want it centered on my page.I'm not all that familiar with css or javascript, and nothing I'm doing is getting my gallery to center.
View 2 Replies
View Related
Apr 20, 2010
I'm trying to write a function to center a div within a parent div, and I'm having a little trouble. Horizontally, it works fine. Vertically, not so much.
This is my function:
function centerObject(idName, idParent) {
var parentLeft = $(idParent).position().left;
var parentWidth = $(idParent).width();
var parentWCenter = parentWidth / 2;
var parentTop = $(idParent).position().top;
var parentHeight = $(idParent).height();
var parentHCenter = parentHeight / 2;
var objWidth = $(idName).width();
var objWCenter = parentLeft + parentWCenter - (objWidth / 2);
var objHeight = $(idName).height();
var objHCenter = Math.abs(parentTop + parentHCenter - (objHeight / 2) - 20);
$(idName).css({left:objWCenter,top:objHCenter});
};
The line with the Math.abs call is necessary because without it, the given div ends up halfway off the page up at the top. At least this way it appears somewhere within the browser. The divs in question are all set to position: absolute, but I've tried setting them to all the other possibilities without luck. Or maybe I missed something. This happens in any browser... IE, FF, Chrome, Safari, etc.
View 2 Replies
View Related
Nov 25, 2010
I have a problem in centering my popup window. I want it centered in the page when it pops up. The problem is in the code that is red. Here's a part of my script:
if (counter == 0){
var myRes = "<html><head>";
myRes += "<title>Popup Window</title>";
myRes += "</head><body>";
myRes += "<div style='text-align:center'>";
myRes += "<p>Search character '<b>" + searchChar + "</b>' not found in text string!</p>";
myRes += "<input type='button' value='Close Window' onclick='window.close()'>";
myRes += "</div>";
myRes += "</body>
</html>";
var popup = window.open("", "Popup", "top=10,left=300,width=300,height=100");
popup.focus();
popup.document.write(myRes);
popup.document.close();
View 7 Replies
View Related
Jun 4, 2009
I have the following DIV, that I need to position in the center of the page, I have the following code, but you can see the div is not exactly center, space I have from the top is not the same I have in the bottom, the space I have from bot side is the same.I was wandering also if I can do this dynamically, meaning the div will receive the width and height in run time, and them I will send the values to my method "centerObj" (How I can get the height and width of the div element.
<html>
<head>
<script>[code]....
View 5 Replies
View Related
Jan 24, 2010
I got a slider that I am using but the problem is that it is using AP Div tags and with that when the browser window resizes the slider moves. what I want to do is center it and keep it from resizing or moving around.When I change it to a regular div it just get all jumbled up.
View 1 Replies
View Related
Mar 2, 2009
I have a main page(html) and an iframe in it.
<html>
<body>
<iframe src="myIframe.html" />
</body>
</html>
In the iframe I have DIV element with a picture/or another element in it. I need to center the DIV element in the iframe, the DIV in the end should be in the center of the iframe(client area), this iframe can be resize, so every time the iframe is resize I need to center the DIV according to the new client area. How I can get the client area and center the DIV? I'm guessing that I will need also the size of the element(picture) to center it, right?
View 2 Replies
View Related
Nov 15, 2010
Im having a bit of an issue with a website im building for a band. The band want a site that is 2500 width so that when the page loads you can either scroll roght or left to view the out of screen material...
i cant find a way of the page loading centered...it is always loading to the far left and all i can do is scroll right...i have uploaded the site to [URL]... I origionally posted this thread in the CSS forum but was instructed this would be a Javascript issue
View 1 Replies
View Related
Nov 4, 2009
I'm using a javascript to center my absolutely-positioned left-aligned site. However, it's not perfectly centered in the browser and I'd like to fix it. I set the width to 788px (embedded Div Layout CSS). Here is the link to the site: [URL]
Below is the javascript code:
window.onresize=positionPage;
String.prototype.trim = function() { return this.replace(/^s+|s+$/, ''); };
function positionPage(){
Width = 0;
if(window.innerWidth){
Width = window.innerWidth;
}if(document.body.clientWidth){
Width = document.body.clientWidth;
}Left = Math.floor((Width - 992) / 2);
if(Left > 0){
document.getElementById("Div-Layout").style.left = Left + "px";
}}
<!--
function MM_reloadPage(init) {
//reloads the window if Nav4 resized
if (init==true) with (navigator) {
if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight;
onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW
|| innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
View 2 Replies
View Related
Sep 7, 2010
I recently found a really nice code that centers a page vertically: [URL].. What I like about it, is that when you zoom in with Chrome, nothing gets cut off. Normally other codes for centering will zoom straight into the middle, and cut off content on the left. The only problem I'm having with it, is that when the page loads in Chrome and Safari, it starts to load at the top of the page, and then quickly jumps down to where it's centered. It looks a little choppy when you're navigating through many pages. I'm wondering if there's a way to get it to load in the correct position where it will stay?
View 3 Replies
View Related
Mar 4, 2010
I've designed a web page that uses several DIVs that use absolute positioning so they can layer on top of each other with transparent shadows. You can view the design here:http:[url]...The client wanted the whole design to center in the window horizontally, and since I can't use margin: 0 auto; to achieve this, I'm using a script that detects the window size using the onLoad operator in the body tag. This is the script:
Code:
<!--
window.onresize= alertSize;
function alertSize() {[code].....
It works, but I don't like that the page snaps back to the left every time a new page loads. Is there a way for the script to detect the window size from the previous page so that the design won't jump if the window hasn't been resized?
View 2 Replies
View Related
Oct 17, 2009
I didn't see this as an option, so I decided to give it a try on my own. I was able to add some lines of code (shown with the > in the margin below) to the jquery.cycle.js script to read in the width of each image and center the slide within the slideshow container // set position and zIndex on all the slides
View 2 Replies
View Related
Jun 26, 2011
I have a div that is set to overflow auto allowing the content to scroll left and right. This is because the content I am putting in it (a series of input boxes) is considerably wider than the containing div. The way it sits, when I start in the first input box and continually tab to the other input boxes, the focus goes from the left of the screen to the right. Once it hits the input box to the right of the screen, some of the input box is hidden to the right. As I tab to the input boxes to the right, each one has a portion of the element cut off by the view window.
What I want to happen is when I start at the left most input box and tab over, as I reach the center of the viewable part of the container, I want the input boxes to continue to center themselves until I reach the last ones. I think that telling each input box to center itself in the visible window of the containing div as it gets focus would work, I just don't know if there is an easy way to accomplish this using javascript I am using the mootools framework if that helps my case any.
View 4 Replies
View Related
Oct 26, 2009
I have absolutely positioned left-aligned elements that I'm attempting to center with javascript.The page briefly shifts to the left when the page is loaded before it centers the page.(I realize that this goal could be achieved with CSS alone but I am hoping for a cure for this javascript solution for now.)The javascript that I'm using is common.js, the onload command is positionPage(); and the div is DivLayout.I don't know if I need to adjust the div, javascript or both.how I can correct the shifting issue?Here is the link to view my issue: http:/tiny.cc/test176
Below is the javascript code:
window.onresize=positionPage;
String.prototype.trim = function() { return this.replace(/^s+|s+$/, ''); };[code]...........
View 7 Replies
View Related
Jan 26, 2009
I managed to smooth out the animations on this page here. However, I'm unsure on how to get the Javascript script (here) to center the first page as well. You'll notice when you click on the main menu items, the script will center the elements on the page, just not at the start.
View 2 Replies
View Related
Feb 13, 2011
I have an issue with my div visibility toggling
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')[code]....
and I do the return false to stop the thing from jumping all over the place, but where i click next, the page scrolls down to center on that point, which is really annoying. How do I stop it?
View 1 Replies
View Related