473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Cannot see all content

Claus Mygind
571 512MB
I have a hidden <div> which I populate and then display relative to the link that activates it.

My problem is this, when the link is near the bottom of the page and the content of the hidden <div> extends below the bottom, I cannot scroll to see it.

I would like to adjust the top of the <div> placement if it should extend below the screen.

Below is the code I use to determine where the <div> should be displayed.
Basically I capture the current mouse position with the event listener ".onmousemove".

If the height of the <div> should exceed the available room I would like to adjust the top location d.style.top = (cY-46) + "px"; to something other than -46 from the relative position.

How can I determine the height of the dynamically created division?
And how can I determine if it is exceeding the bottom of the page?


Expand|Select|Wrap|Line Numbers
  1. var cX = 0; var cY = 0; var rX = 0; var rY = 0;
  2.  
  3. document.onmousemove = UpdateCursorPosition; 
  4.  
  5. function UpdateCursorPosition(e)
  6.     cX = e.pageX; cY = e.pageY;
  7. }
  8.  
  9. function AssignPosition(d) 
  10. {
  11.     if(self.pageYOffset) 
  12.     {
  13.         rX = self.pageXOffset;
  14.         rY = self.pageYOffset;
  15.     }else if(document.documentElement && document.documentElement.scrollTop) 
  16.     {
  17.         rX = document.documentElement.scrollLeft;
  18.         rY = document.documentElement.scrollTop;
  19.     }
  20.     else if(document.body) 
  21.     {
  22.         rX = document.body.scrollLeft;
  23.         rY = document.body.scrollTop;
  24.     }
  25.     if(document.all) 
  26.     {
  27.         cX += rX; 
  28.         cY += rY;
  29.     }
  30.     d.style.left = (cX+107) + "px";
  31.     d.style.top = (cY-46) + "px";
  32. }
  33.  
  34. function ShowContent(d) 
  35. {
  36.     if(d.length < 1) 
  37.     { 
  38.         return; 
  39.     }
  40.     var dd = document.getElementById(d);
  41.     AssignPosition(dd);
  42.     dd.style.display = "block";
  43. }
  44.  
  45.  
  46.  
Jul 22 '09 #1
4 1599
hsriat
1,654 Expert 1GB
@Claus Mygind
You can do that by returning div.style.height, BUT only if you have set it, and have not let it attain the height according to its inner elements.

If you have just text inside the div, then you can calculate approx. height by counting the number of chars in the text, and font size.

@Claus Mygind
Calculate it with div's top y co-od, div's height and screen height (screen.availHeight)
Jul 22 '09 #2
gits
5,390 Expert Mod 4TB
may be the getComputedStyle() might help? have a look here for the idea and usage.

kind regards
Jul 23 '09 #3
Claus Mygind
571 512MB
@gits
Ok that was a very handy article and did get to the point where I can calculate if the popup I want to display is going to be longer than the available space. Also I can calculate what the new position should be based on the amount of overflow (see code below).

Now my problem is getting the <div> element to move to that new location.

In the code I have cobbled the following together.
1. Two <div> elements have been assigned style attributes "fullWidth" and "allContacts"

2. an event listener "onmousemove" tied to the document detects the location of the link in document when mouse is clicked.

3. The position of the "allContacts" <div> is assigned an offset based on this location.

4. Then from the article you suggested, I am able to calculate the top and height of the "allContacts". I compare that to the height of the "fullWidth" <div> and if the total is greater than height of "fullWidth", I then calculate the new top, where I would like to move the element to.

But how do I get it to move once it has been displayed?

One final note - I am working in FireFox and only want a solution for FireFox.

Expand|Select|Wrap|Line Numbers
  1. <STYLE TYPE="text/css" >
  2. #allContacts {font-size: 16px;
  3.     padding: 10px;
  4.     width: 50%;
  5.     border-width: 1px;
  6.     border-style: solid;
  7.     border-color: #cc0000;
  8. }
  9. #fullWidth {
  10.      position: absolute;
  11.      white-space: nowrap; 
  12.      left: 0%; 
  13.       top: 25px;
  14.       width: 99%;
  15.       color: #333333;
  16.       padding:5px;
  17.       font-size: 10pt;
  18.         overflow: hidden;
  19.       z-index: 98;
  20.  }
  21. </STYLE>
  22.  
  23. <SCRIPT LANGUAGE="JavaScript">
  24. <!--
  25. var cX = 0; var cY = 0; var rX = 0; var rY = 0;
  26.  
  27. document.onmousemove = UpdateCursorPosition; 
  28.  
  29. function UpdateCursorPosition(e)
  30.     cX = e.pageX; cY = e.pageY;
  31. }
  32.  
  33. function AssignPosition(d) 
  34. {
  35.     if(self.pageYOffset) 
  36.     {
  37.         rX = self.pageXOffset;
  38.         rY = self.pageYOffset;
  39.     }else if(document.documentElement && document.documentElement.scrollTop) 
  40.     {
  41.         rX = document.documentElement.scrollLeft;
  42.         rY = document.documentElement.scrollTop;
  43.     }
  44.     else if(document.body) 
  45.     {
  46.         rX = document.body.scrollLeft;
  47.         rY = document.body.scrollTop;
  48.     }
  49.     if(document.all) 
  50.     {
  51.         cX += rX; 
  52.         cY += rY;
  53.     }
  54.     d.style.left = (cX+107) + "px";
  55.     d.style.top = (cY-46) + "px";
  56. }
  57.  
  58. function ShowContent(d) 
  59. {
  60.     if(d.length < 1) 
  61.     { 
  62.         return; 
  63.     }
  64.     var dd = document.getElementById(d);
  65.     AssignPosition(dd);
  66.     dd.style.display = "block";
  67. getOff();
  68. }
  69.  
  70. //get current dimensions and position of an element
  71. function getOff()
  72. {
  73.     var x = document.getElementById('allContacts');
  74.     var y = document.getElementById('fullWidth');
  75.     if ( x.offsetHeight + x.offsetTop > y.offsetHeight)
  76.     {
  77.         x.top = (x.offsetTop - ((x.offsetHeight + x.offsetTop) - y.offsetHeight))+ 'px';
  78. alert(x.top);
  79.     }
  80.     return;
  81. }
  82. //-->
  83. </SCRIPT>
  84.  
  85. <a href="javascript:ShowContent('allContacts')"    
  86.               id="con_"
  87.               onclick="changeStatus(this)";
  88.               return false;"
  89. > View all contacts </a>
  90.  
  91.  
  92.  
Jul 23 '09 #4
Claus Mygind
571 512MB
I got the final piece of the puzzle. Just one minor adjustment to the code above.

I only needed to modify the line

x.top = ....

to

x.style.top = ...

Expand|Select|Wrap|Line Numbers
  1. //get current dimensions and position of an element
  2. function getOff()
  3. {
  4.     var x = document.getElementById('allContacts');
  5.     var y = document.getElementById('fullWidth');
  6.     if ( x.offsetHeight + x.offsetTop > y.offsetHeight)
  7.     {
  8.         x.style.top = (x.offsetTop - ((x.offsetHeight + x.offsetTop) - y.offsetHeight))+ 'px';
  9.     }
  10.     return;
  11. }
  12.  
Jul 23 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: nc | last post by:
My iterator can find my collection when my Action class calls my jsp directly, however when my Action class calls an html file that is set up with IFrames (one of which is loading that same jsp), I...
10
by: mike | last post by:
regards: I use Jtidy (api) to translate a HTML file into a "XHTML file". But The "XHTML file" cannot be identified by nokia 6600. Do I miss something important? Or this is Jtidy's weakness or...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
2
by: Tim Reynolds | last post by:
Team, When my web service throws an exception and I am debugging on my PC - I get the exception back in my browser fine. My web.config shows <customErrors mode="Off"/> and this is working well. ...
2
by: moondaddy | last post by:
I have a simple sample site I'm building in asp.net 2.0. I created a master page and a default.aspx content page in the project's root directory. Then I created a subfolder called content and...
1
by: juergen | last post by:
Hi, there are many postings on this subject, I have read them put don't have an answer. I get these warnings: Cannot send session cookie - headers already sent in, but my php-scripts are okay. ...
5
by: nasse | last post by:
I am getting the following error msg whenever I try to login. I tried to turn my output_buffering = On in my php.ini but is not working for me. Would you please help me: Warning: Cannot modify...
2
by: karinmorena | last post by:
I'm having 4 errors, I'm very new at this and I would appreciate your input. The error I get is: Week5MortgageGUI.java:151:cannot find symbol symbol: method allInterest(double,double,double)...
7
by: php_mysql_beginer911 | last post by:
Hi .. hope someone will help i am trying to figure it out why i cannot post string "union select" every time i try to post data which content union and select .. the page doesn't get posted and...
13
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
This is a follow-up to my post "Silverlight video doesn't work when file is streamed from handler in ASP.net" at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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,...

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.