473,786 Members | 2,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get object position and change it?

Hi,

I do not know where should I start to solve this problem.

I have a calendar inside a div on my webpage which will show /hide when
user click a button. but the button is almost at the bottom of my
webpage, I am using position :absolute for the div so everytime when
the div shows, it will "drop down" cause the vertical scroll bar
appears on web browser and the user have to scroll down to see the
whole calendar. I was trying to change the div position (e.g if it is
near the bottom of webbrowser then "drop-up") when the div is showing.

My question is
How can I know its position is near the bottom of web browser? (how can
I know the height of the browser)
How can I change the position of this div?

Thanks for any help and example links.

-rockdale

Sep 7 '06 #1
2 28420
Hey,
I'd be able to help a lot better if I could see the site, so I could
know what you're trying to do. However, I can help you with your
questions.

You can get the position of the object by doing this:
myDiv = document.getEle mentById('calen darDiv');
divPos = myDiv.style.top ;

You can then check it against the size of the browser. In every browser
but IE, window.innerHei ght will tell you your window size. So use this
code to get your height

if( typeof(window.i nnerHeight) == 'number' ) {
//Everything but IE
wHeight = window.innerHei ght;
else if( document.docume ntElement && (
document.docume ntElement.clien tWidth ||
document.docume ntElement.clien tHeight ) ) {
//IE 6+ in 'standards compliant mode'
wHeight = document.docume ntElement.clien tHeight;
} else if( document.body && ( document.body.c lientWidth ||
document.body.c lientHeight ) ) {
//IE 4 compatible
wHeight = document.body.c lientHeight;
}

Now that you have your window height, test to see where your div is in
proportion to the middle of the screen.

if (myDiv.style.to p (wHeight/2)){
//it is more than halfway down the page, pop it at the bottom
myDiv.style.top = (wHeight-myDiv.style.hei ght) //You may need to play
with this a bit.
} else {
//it is more than halfway up the page, pop it at the top
myDiv.style.top = 0;
}

I hope this helped and I hope it's what you were looking to do. And of
course you'd have to replace the 'calendarDiv' with the id you assigned
your div (give it one if you haven't, and make sure it's unique).
Again, if you have a link, post it and I will take a look to see if I
am assuming things correctly. Have a good one!

~Ben~

ro************@ gmail.com wrote:
Hi,

I do not know where should I start to solve this problem.

I have a calendar inside a div on my webpage which will show /hide when
user click a button. but the button is almost at the bottom of my
webpage, I am using position :absolute for the div so everytime when
the div shows, it will "drop down" cause the vertical scroll bar
appears on web browser and the user have to scroll down to see the
whole calendar. I was trying to change the div position (e.g if it is
near the bottom of webbrowser then "drop-up") when the div is showing.

My question is
How can I know its position is near the bottom of web browser? (how can
I know the height of the browser)
How can I change the position of this div?

Thanks for any help and example links.

-rockdale
Sep 7 '06 #2
Thanks for the code sample. I will try it ans let you updated.

Again, thanks
-rockdale

Beni Rose wrote:
Hey,
I'd be able to help a lot better if I could see the site, so I could
know what you're trying to do. However, I can help you with your
questions.

You can get the position of the object by doing this:
myDiv = document.getEle mentById('calen darDiv');
divPos = myDiv.style.top ;

You can then check it against the size of the browser. In every browser
but IE, window.innerHei ght will tell you your window size. So use this
code to get your height

if( typeof(window.i nnerHeight) == 'number' ) {
//Everything but IE
wHeight = window.innerHei ght;
else if( document.docume ntElement && (
document.docume ntElement.clien tWidth ||
document.docume ntElement.clien tHeight ) ) {
//IE 6+ in 'standards compliant mode'
wHeight = document.docume ntElement.clien tHeight;
} else if( document.body && ( document.body.c lientWidth ||
document.body.c lientHeight ) ) {
//IE 4 compatible
wHeight = document.body.c lientHeight;
}

Now that you have your window height, test to see where your div is in
proportion to the middle of the screen.

if (myDiv.style.to p (wHeight/2)){
//it is more than halfway down the page, pop it at the bottom
myDiv.style.top = (wHeight-myDiv.style.hei ght) //You may need to play
with this a bit.
} else {
//it is more than halfway up the page, pop it at the top
myDiv.style.top = 0;
}

I hope this helped and I hope it's what you were looking to do. And of
course you'd have to replace the 'calendarDiv' with the id you assigned
your div (give it one if you haven't, and make sure it's unique).
Again, if you have a link, post it and I will take a look to see if I
am assuming things correctly. Have a good one!

~Ben~

ro************@ gmail.com wrote:
Hi,

I do not know where should I start to solve this problem.

I have a calendar inside a div on my webpage which will show /hide when
user click a button. but the button is almost at the bottom of my
webpage, I am using position :absolute for the div so everytime when
the div shows, it will "drop down" cause the vertical scroll bar
appears on web browser and the user have to scroll down to see the
whole calendar. I was trying to change the div position (e.g if it is
near the bottom of webbrowser then "drop-up") when the div is showing.

My question is
How can I know its position is near the bottom of web browser? (how can
I know the height of the browser)
How can I change the position of this div?

Thanks for any help and example links.

-rockdale
Sep 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6372
by: Matt | last post by:
Hi group, Here's a problem I've been trying to solve for the past several weeks. I have the standard WebBrowser object added to a form so it can access websites, and I have it load a default page once the form is launched. I now want to automatically fill out a specific text-field found within the web-page that the WebBrowser object has open. Right now I am using the following code to accomplish it: ...
3
9843
by: Catherine Lynn Smith | last post by:
I am creating a webpage with dhtml <DIV> layers and I want a link on one layer to modify the content on another but I seem to keep running into errors. Basically I create a layer in the middle of the screen that initially comes up with a gif image of a house: <!-- start "house" layer definition for center of screen --> <DIV id="house" style="position:absolute; left:140px; top:137px; width:510px; height:325px; z-index:2"><img...
3
4326
by: Mr. x | last post by:
Hello, I have simple table <table id = "mytable" ....> .... </table> I want to get the left position of the table. Everything I did getting wrong :
7
5853
by: GfxGuy | last post by:
I've seen this problem posted a million times, but I've read through all of them and can't figure out what I'm doing wrong. Simple example (this is the whole file, no editing): ---------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html>
3
3175
by: Poewood | last post by:
Okay here are four classes for a pocket pc program: Input, fpositional, ComboBoxArray and TextBoxArray. The "input" class is the form. I use the fpositional class to handle most of the functions for the objects on the form, in addition the The objects are created in the fpositional class and affixed to the Input form through the fpositional constructor which takes the form as an argument. The ComboBox and TextBox Array classes hold the...
1
3321
by: D. Yates | last post by:
Hi, I retrieved the employee table from the Pubs database into a single dataset called, dataSet12. I dropped two textbox controls and a datagrid control onto the same form and bound the controls at design time to dataSet12's employee table. Now I want to move through the data by pressing a button.... This code will change the data in the text boxes: this.BindingContext.Position += 1;
4
1742
by: Jesse Villani | last post by:
I will get this eventually, I have a combobox on a form which is bound to a dataset and displays correct values in the list. When i select a value from the list, i check to see what is the current row in a bindingManagerBase object is in the selectedValue event handler code. I print out, on labels the following values: bmb.Count and bmb.Position where bmb is the bindingManagerBase object.
12
5556
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. Foo = function(type) { this.num = 0; this.type = type this.trigger(); } Foo.prototype.trigger = function() {
9
5067
by: koschwitz | last post by:
Hi, I hope you guys can help me make this simple application work. I'm trying to create a form displaying 3 circles, which independently change colors 3 times after a random time period has passed. I'm struggling with making the delegate/invoke thing work, as I know GUI objects aren't thread-safe. I don't quite understand the concept I'm supposed to use to modify the GUI thread-safe. Below is my form and my Circle class. Currently,...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9496
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8989
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.