469,361 Members | 2,276 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,361 developers. It's quick & easy.

Problems with "Rich HTML Balloon Tooltip"

mikek12004
200 100+
1) Script Title: Rich HTML Balloon Tooltip

2) Script URL :http://www.dynamicdrive.com/dynamici...oontooltip.htm

3) Problem Description:
See this page
General Music
for links you can see without scrolling down the div the tooltip is shown at the desired place but when you scroll donw the div the tooltip's position gets all messed up, e.g in the last "ΤΙΤΛΟΣ ALBUM" (which means Title of album ) the tooltip gets in front of the link and so the user cannot press the link!
Thous far it has proven a very neat easy to implement script which has added a lot visually to my site, for anyone capable of thinking some modification to overcome the div problem any suggestions?
Many thanks for your time
Nov 25 '08 #1
8 4015
acoder
16,027 Expert Mod 8TB
You need to add scrollTop into the equation. See Element Dimensions.
Nov 25 '08 #2
mikek12004
200 100+
Should I add or substract the scrollTop property and from which lines?
Apologise for the trouble but do not know much of Javascript plus the code is not mine, for convinience I have posted the js below.
Expand|Select|Wrap|Line Numbers
  1. //Rich HTML Balloon Tooltip: http://www.dynamicdrive.com/dynamicindex5/balloontooltip.htm
  2. //Created: September 10th, 2006
  3.  
  4. var disappeardelay=250  //tooltip disappear delay (in miliseconds)
  5. var verticaloffset=0 //vertical offset of tooltip from anchor link, if any
  6. var enablearrowhead=1 //0 or 1, to disable or enable the arrow image
  7. var arrowheadimg=["images/arrowdown.gif", "images/arrowup.gif"] //path to down and up arrow images
  8. var arrowheadheight=14 //height of arrow image (amount to reveal)
  9.  
  10. /////No further editting needed
  11.  
  12. var ie=document.all
  13. var ns6=document.getElementById&&!document.all
  14. verticaloffset=(enablearrowhead)? verticaloffset+arrowheadheight : verticaloffset;
  15.  
  16. function getposOffset(what, offsettype){
  17. var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
  18. var parentEl=what.offsetParent;
  19. while (parentEl!=null){
  20. totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
  21. parentEl=parentEl.offsetParent;
  22. }
  23. return totaloffset;
  24. }
  25.  
  26. function showhide(obj, e){
  27. dropmenuobj.style.left=dropmenuobj.style.top="-500px"
  28. if (e.type=="mouseover")
  29. obj.visibility="visible"
  30. }
  31.  
  32. function iecompattest(){
  33. return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
  34. }
  35.  
  36. function clearbrowseredge(obj, whichedge){
  37. if (whichedge=="rightedge"){
  38. edgeoffsetx=0
  39. var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
  40. dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
  41. if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
  42. edgeoffsetx=dropmenuobj.contentmeasure-obj.offsetWidth
  43. return edgeoffsetx
  44. }
  45. else{
  46. edgeoffsety=0
  47. var topedge=ie && !window.opera? iecompattest().scrollTop : window.pageYOffset
  48. var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
  49. dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
  50. if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure) //move up?
  51. edgeoffsety=dropmenuobj.contentmeasure+obj.offsetHeight+(verticaloffset*2)
  52. return edgeoffsety
  53. }
  54. }
  55.  
  56. function displayballoontip(obj, e){ //main ballooon tooltip function
  57. if (window.event) event.cancelBubble=true
  58. else if (e.stopPropagation) e.stopPropagation()
  59. if (typeof dropmenuobj!="undefined") //hide previous tooltip?
  60. dropmenuobj.style.visibility="hidden"
  61. clearhidemenu()
  62. //obj.onmouseout=delayhidemenu
  63. dropmenuobj=document.getElementById(obj.getAttribute("rel"))
  64. showhide(dropmenuobj.style, e)
  65. dropmenuobj.x=getposOffset(obj, "left")
  66. dropmenuobj.y=getposOffset(obj, "top")+verticaloffset
  67. dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
  68. dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
  69. if (enablearrowhead)
  70. displaytiparrow()
  71. }
  72.  
  73. function displaytiparrow(){ //function to display optional arrow image associated with tooltip
  74. tiparrow=document.getElementById("arrowhead")
  75. tiparrow.src=(edgeoffsety!=0)? arrowheadimg[0] : arrowheadimg[1]
  76. var ieshadowwidth=(dropmenuobj.filters && dropmenuobj.filters[0])? dropmenuobj.filters[0].Strength-1 : 0
  77. //modify "left" value depending on whether there's no room on right edge of browser to display it, respectively
  78. tiparrow.style.left=(edgeoffsetx!=0)? parseInt(dropmenuobj.style.left)+dropmenuobj.offsetWidth-tiparrow.offsetWidth-10+"px" : parseInt(dropmenuobj.style.left)+5+"px"
  79. //modify "top" value depending on whether there's no room on right edge of browser to display it, respectively
  80. tiparrow.style.top=(edgeoffsety!=0)? parseInt(dropmenuobj.style.top)+dropmenuobj.offsetHeight-tiparrow.offsetHeight-ieshadowwidth+arrowheadheight+"px" : parseInt(dropmenuobj.style.top)-arrowheadheight+"px"
  81. tiparrow.style.visibility="visible"
  82. }
  83.  
  84. function delayhidemenu(){
  85. delayhide=setTimeout("dropmenuobj.style.visibility='hidden'; dropmenuobj.style.left=0; if (enablearrowhead) tiparrow.style.visibility='hidden'",disappeardelay)
  86. }
  87.  
  88. function clearhidemenu(){
  89. if (typeof delayhide!="undefined")
  90. clearTimeout(delayhide)
  91. }
  92.  
  93. function reltoelement(linkobj){ //tests if a link has "rel" defined and it's the ID of an element on page
  94. var relvalue=linkobj.getAttribute("rel")
  95. return (relvalue!=null && relvalue!="" && document.getElementById(relvalue)!=null && document.getElementById(relvalue).className=="balloonstyle")? true : false
  96. }
  97.  
  98. function initalizetooltip(){
  99. var all_links=document.getElementsByTagName("a")
  100. if (enablearrowhead){
  101. tiparrow=document.createElement("img")
  102. tiparrow.setAttribute("src", arrowheadimg[0])
  103. tiparrow.setAttribute("id", "arrowhead")
  104. document.body.appendChild(tiparrow)
  105. }
  106. for (var i=0; i<all_links.length; i++){
  107. if (reltoelement(all_links[i])){ //if link has "rel" defined and it's the ID of an element on page
  108. all_links[i].onmouseover=function(e){
  109. var evtobj=window.event? window.event : e
  110. displayballoontip(this, evtobj)
  111. }
  112. all_links[i].onmouseout=delayhidemenu
  113. }
  114. }
  115. }
  116.  
  117. if (window.addEventListener)
  118. window.addEventListener("load", initalizetooltip, false)
  119. else if (window.attachEvent)
  120. window.attachEvent("onload", initalizetooltip)
  121. else if (document.getElementById)
  122. window.onload=initalizetooltip
  123.  
  124.  
Nov 25 '08 #3
mikek12004
200 100+
In the above code wherever offsetTop (only in the function getposOffset) I substracted scrolltop now in IE works fine but in firefox is still the same any idea why?
The code now is
Expand|Select|Wrap|Line Numbers
  1. //Rich HTML Balloon Tooltip: http://www.dynamicdrive.com/dynamicindex5/balloontooltip.htm
  2. //Created: September 10th, 2006
  3.  
  4. var disappeardelay=250  //tooltip disappear delay (in miliseconds)
  5. var verticaloffset=0 //vertical offset of tooltip from anchor link, if any
  6. var enablearrowhead=1 //0 or 1, to disable or enable the arrow image
  7. var arrowheadimg=["images/arrowdown.gif", "images/arrowup.gif"] //path to down and up arrow images
  8. var arrowheadheight=14 //height of arrow image (amount to reveal)
  9.  
  10. /////No further editting needed
  11.  
  12. var ie=document.all
  13. var ns6=document.getElementById&&!document.all
  14. verticaloffset=(enablearrowhead)? verticaloffset+arrowheadheight : verticaloffset;
  15.  
  16. function getposOffset(what, offsettype){
  17. var totaloffset=(offsettype=="left")? what.offsetLeft-what.scrollLeft  : what.offsetTop-what.scrollTop;
  18. var parentEl=what.offsetParent;
  19. while (parentEl!=null){
  20. totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft-parentEl.scrollLeft : totaloffset+parentEl.offsetTop-parentEl.scrollTop;
  21. parentEl=parentEl.offsetParent;
  22. }
  23. return totaloffset;
  24. }
  25.  
  26. function showhide(obj, e){
  27. dropmenuobj.style.left=dropmenuobj.style.top="-500px"
  28. if (e.type=="mouseover")
  29. obj.visibility="visible"
  30. }
  31.  
  32. function iecompattest(){
  33. return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
  34. }
  35.  
  36. function clearbrowseredge(obj, whichedge){
  37. if (whichedge=="rightedge"){
  38. edgeoffsetx=0
  39. var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
  40. dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
  41. if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
  42. edgeoffsetx=dropmenuobj.contentmeasure-obj.offsetWidth
  43. return edgeoffsetx
  44. }
  45. else{
  46. edgeoffsety=0
  47. var topedge=ie && !window.opera? iecompattest().scrollTop : window.pageYOffset
  48. var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
  49. dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
  50. if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure) //move up?
  51. edgeoffsety=dropmenuobj.contentmeasure+obj.offsetHeight+(verticaloffset*2)
  52. return edgeoffsety
  53. }
  54. }
  55.  
  56. function displayballoontip(obj, e){ //main ballooon tooltip function
  57. if (window.event) event.cancelBubble=true
  58. else if (e.stopPropagation) e.stopPropagation()
  59. if (typeof dropmenuobj!="undefined") //hide previous tooltip?
  60. dropmenuobj.style.visibility="hidden"
  61. clearhidemenu()
  62. //obj.onmouseout=delayhidemenu
  63. dropmenuobj=document.getElementById(obj.getAttribute("rel"))
  64. showhide(dropmenuobj.style, e)
  65. dropmenuobj.x=getposOffset(obj, "left")
  66. dropmenuobj.y=getposOffset(obj, "top")+verticaloffset
  67. dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
  68. dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
  69. if (enablearrowhead)
  70. displaytiparrow()
  71. }
  72.  
  73. function displaytiparrow(){ //function to display optional arrow image associated with tooltip
  74. tiparrow=document.getElementById("arrowhead")
  75. tiparrow.src=(edgeoffsety!=0)? arrowheadimg[0] : arrowheadimg[1]
  76. var ieshadowwidth=(dropmenuobj.filters && dropmenuobj.filters[0])? dropmenuobj.filters[0].Strength-1 : 0
  77. //modify "left" value depending on whether there's no room on right edge of browser to display it, respectively
  78. tiparrow.style.left=(edgeoffsetx!=0)? parseInt(dropmenuobj.style.left)+dropmenuobj.offsetWidth-tiparrow.offsetWidth-10+"px" : parseInt(dropmenuobj.style.left)+5+"px"
  79. //modify "top" value depending on whether there's no room on right edge of browser to display it, respectively
  80. tiparrow.style.top=(edgeoffsety!=0)? parseInt(dropmenuobj.style.top)+dropmenuobj.offsetHeight-tiparrow.offsetHeight-ieshadowwidth+arrowheadheight+"px" : parseInt(dropmenuobj.style.top)-arrowheadheight+"px"
  81. tiparrow.style.visibility="visible"
  82. }
  83.  
  84. function delayhidemenu(){
  85. delayhide=setTimeout("dropmenuobj.style.visibility='hidden'; dropmenuobj.style.left=0; if (enablearrowhead) tiparrow.style.visibility='hidden'",disappeardelay)
  86. }
  87.  
  88. function clearhidemenu(){
  89. if (typeof delayhide!="undefined")
  90. clearTimeout(delayhide)
  91. }
  92.  
  93. function reltoelement(linkobj){ //tests if a link has "rel" defined and it's the ID of an element on page
  94. var relvalue=linkobj.getAttribute("rel")
  95. return (relvalue!=null && relvalue!="" && document.getElementById(relvalue)!=null && document.getElementById(relvalue).className=="balloonstyle")? true : false
  96. }
  97.  
  98. function initalizetooltip(){
  99. var all_links=document.getElementsByTagName("a")
  100. if (enablearrowhead){
  101. tiparrow=document.createElement("img")
  102. tiparrow.setAttribute("src", arrowheadimg[0])
  103. tiparrow.setAttribute("id", "arrowhead")
  104. document.body.appendChild(tiparrow)
  105. }
  106. for (var i=0; i<all_links.length; i++){
  107. if (reltoelement(all_links[i])){ //if link has "rel" defined and it's the ID of an element on page
  108. all_links[i].onmouseover=function(e){
  109. var evtobj=window.event? window.event : e
  110. displayballoontip(this, evtobj)
  111. }
  112. all_links[i].onmouseout=delayhidemenu
  113. }
  114. }
  115. }
  116.  
  117. if (window.addEventListener)
  118. window.addEventListener("load", initalizetooltip, false)
  119. else if (window.attachEvent)
  120. window.attachEvent("onload", initalizetooltip)
  121. else if (document.getElementById)
  122. window.onload=initalizetooltip
  123.  
Jan 5 '09 #4
mikek12004
200 100+
As said in previous post in my page I use the "Rich HTML Balloon Tooltip" which can be found here :
Dynamic Drive DHTML Scripts- Rich HTML Balloon Tooltip
Great script helped a lot but when I used it inside a div for elements that neede to be scrolled to reach the ballon tip was dispalyed at the position they would had in the page without the page. In another thread acoder suggested to use scrolltop wich I did and worked but only in IE, in firefox/safari I get still the same but why?
the .js is
Expand|Select|Wrap|Line Numbers
  1. //Rich HTML Balloon Tooltip: http://www.dynamicdrive.com/dynamicindex5/balloontooltip.htm
  2. //Created: September 10th, 2006
  3.  
  4. var disappeardelay=250  //tooltip disappear delay (in miliseconds)
  5. var verticaloffset=0 //vertical offset of tooltip from anchor link, if any
  6. var enablearrowhead=1 //0 or 1, to disable or enable the arrow image
  7. var arrowheadimg=["images/arrowdown.gif", "images/arrowup.gif"] //path to down and up arrow images
  8. var arrowheadheight=14 //height of arrow image (amount to reveal)
  9.  
  10. /////No further editting needed
  11.  
  12. var ie=document.all
  13. var ns6=document.getElementById&&!document.all
  14. verticaloffset=(enablearrowhead)? verticaloffset+arrowheadheight : verticaloffset;
  15.  
  16. function getposOffset(what, offsettype){
  17. var totaloffset=(offsettype=="left")? what.offsetLeft-what.scrollLeft  : what.offsetTop-what.scrollTop;
  18. var parentEl=what.offsetParent;
  19. while (parentEl!=null){
  20. totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft-parentEl.scrollLeft : totaloffset+parentEl.offsetTop-parentEl.scrollTop;
  21. parentEl=parentEl.offsetParent;
  22. }
  23. return totaloffset;
  24. }
  25.  
  26. function showhide(obj, e){
  27. dropmenuobj.style.left=dropmenuobj.style.top="-500px"
  28. if (e.type=="mouseover")
  29. obj.visibility="visible"
  30. }
  31.  
  32. function iecompattest(){
  33. return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
  34. }
  35.  
  36. function clearbrowseredge(obj, whichedge){
  37. if (whichedge=="rightedge"){
  38. edgeoffsetx=0
  39. var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
  40. dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
  41. if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
  42. edgeoffsetx=dropmenuobj.contentmeasure-obj.offsetWidth
  43. return edgeoffsetx
  44. }
  45. else{
  46. edgeoffsety=0
  47. var topedge=ie && !window.opera? iecompattest().scrollTop : window.pageYOffset
  48. var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
  49. dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
  50. if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure) //move up?
  51. edgeoffsety=dropmenuobj.contentmeasure+obj.offsetHeight+(verticaloffset*2)
  52. return edgeoffsety
  53. }
  54. }
  55.  
  56. function displayballoontip(obj, e){ //main ballooon tooltip function
  57. if (window.event) event.cancelBubble=true
  58. else if (e.stopPropagation) e.stopPropagation()
  59. if (typeof dropmenuobj!="undefined") //hide previous tooltip?
  60. dropmenuobj.style.visibility="hidden"
  61. clearhidemenu()
  62. //obj.onmouseout=delayhidemenu
  63. dropmenuobj=document.getElementById(obj.getAttribute("rel"))
  64. showhide(dropmenuobj.style, e)
  65. dropmenuobj.x=getposOffset(obj, "left")
  66. dropmenuobj.y=getposOffset(obj, "top")+verticaloffset
  67. dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
  68. dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
  69. if (enablearrowhead)
  70. displaytiparrow()
  71. }
  72.  
  73. function displaytiparrow(){ //function to display optional arrow image associated with tooltip
  74. tiparrow=document.getElementById("arrowhead")
  75. tiparrow.src=(edgeoffsety!=0)? arrowheadimg[0] : arrowheadimg[1]
  76. var ieshadowwidth=(dropmenuobj.filters && dropmenuobj.filters[0])? dropmenuobj.filters[0].Strength-1 : 0
  77. //modify "left" value depending on whether there's no room on right edge of browser to display it, respectively
  78. tiparrow.style.left=(edgeoffsetx!=0)? parseInt(dropmenuobj.style.left)+dropmenuobj.offsetWidth-tiparrow.offsetWidth-10+"px" : parseInt(dropmenuobj.style.left)+5+"px"
  79. //modify "top" value depending on whether there's no room on right edge of browser to display it, respectively
  80. tiparrow.style.top=(edgeoffsety!=0)? parseInt(dropmenuobj.style.top)+dropmenuobj.offsetHeight-tiparrow.offsetHeight-ieshadowwidth+arrowheadheight+"px" : parseInt(dropmenuobj.style.top)-arrowheadheight+"px"
  81. tiparrow.style.visibility="visible"
  82. }
  83.  
  84. function delayhidemenu(){
  85. delayhide=setTimeout("dropmenuobj.style.visibility='hidden'; dropmenuobj.style.left=0; if (enablearrowhead) tiparrow.style.visibility='hidden'",disappeardelay)
  86. }
  87.  
  88. function clearhidemenu(){
  89. if (typeof delayhide!="undefined")
  90. clearTimeout(delayhide)
  91. }
  92.  
  93. function reltoelement(linkobj){ //tests if a link has "rel" defined and it's the ID of an element on page
  94. var relvalue=linkobj.getAttribute("rel")
  95. return (relvalue!=null && relvalue!="" && document.getElementById(relvalue)!=null && document.getElementById(relvalue).className=="balloonstyle")? true : false
  96. }
  97.  
  98. function initalizetooltip(){
  99. var all_links=document.getElementsByTagName("a")
  100. if (enablearrowhead){
  101. tiparrow=document.createElement("img")
  102. tiparrow.setAttribute("src", arrowheadimg[0])
  103. tiparrow.setAttribute("id", "arrowhead")
  104. document.body.appendChild(tiparrow)
  105. }
  106. for (var i=0; i<all_links.length; i++){
  107. if (reltoelement(all_links[i])){ //if link has "rel" defined and it's the ID of an element on page
  108. all_links[i].onmouseover=function(e){
  109. var evtobj=window.event? window.event : e
  110. displayballoontip(this, evtobj)
  111. }
  112. all_links[i].onmouseout=delayhidemenu
  113. }
  114. }
  115. }
  116.  
  117. if (window.addEventListener)
  118. window.addEventListener("load", initalizetooltip, false)
  119. else if (window.attachEvent)
  120. window.attachEvent("onload", initalizetooltip)
  121. else if (document.getElementById)
  122. window.onload=initalizetooltip
  123.  
  124.  
what I did was insert the scrollTop in lines 17 and 20 (its in the getposOffset function) I suspect lines 47 and 48 but I cannot be sure
Jan 7 '09 #5
acoder
16,027 Expert Mod 8TB
This link may help.
Jan 9 '09 #6
mikek12004
200 100+
You have given me this link in your previous post, did I miss something?
In the above code wherever offsetTop (only in the function getposOffset) I substracted scrolltop in lines 17 and 20 I couldn't find anyother point where he calculates these properties, now in IE works fine but only there why? the only lines where I could see a separation based on the browser is in lines 47 and 48 but I think of what to do any tips?
greatly appreciate your time
Jan 23 '09 #7
acoder
16,027 Expert Mod 8TB
Oh, so I did! Sorry, I didn't realise. In my defence, I could say that it was 1 and a half months later!

I haven't got time to look at this properly, but what I would suggest you do is use a debugging tool like Firebug to see the values as they change to see what they are and what they should be.
Jan 23 '09 #8
mikek12004
200 100+
Yep 1 nad a half moth since the lat post and more than two since I have this little ermm...problem well, hopefully someine with better knowledge in js than me will see the posted code and figure it out before I find the time and (and the effort) to learn a bit more and correct it myself
thanks anyhow you are always a great help ;)
Jan 26 '09 #9

Post your reply

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

Similar topics

28 posts views Thread by petermichaux | last post: by
2 posts views Thread by pleaseSeeFooter | last post: by
2 posts views Thread by Jim Heavey | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.