Simple Javascript Graphics

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Mar 2008
Posts: 31
Reputation: kinger29 is an unknown quantity at this point 
Solved Threads: 1
kinger29 kinger29 is offline Offline
Light Poster

Simple Javascript Graphics

 
0
  #1
Apr 22nd, 2009
I want a box/frame/applet on my html webpage that will display an image and depending on where the user clicks i want text to popup/disappear somewhere else in the image. Does anyone know how to do this in javascript. Sorry Im new to web development and couldn't figure out how to do it in php. Thanks!
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,200
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 486
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Re: Simple Javascript Graphics

 
-1
  #2
Apr 22nd, 2009
The above can be done through applet and no need for JavaScript. However if you insist on JavaScript solution of which I'm not sure can be done, then you are in wrong section (Java is not JavaScript) press Flag Bad Post option next to your original post and write "Please move to JavaScript section".
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 856
Reputation: Airshow is on a distinguished road 
Solved Threads: 122
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: Simple Javascript Graphics

 
0
  #3
Apr 25th, 2009
Kinger,

I'm away from home at the mo' and it's getting late. I'll post a DHTML solution a.s.a.p. It will employ HTML, CSS and JavaScript.

Airshow
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 856
Reputation: Airshow is on a distinguished road 
Solved Threads: 122
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark

Re: Simple Javascript Graphics

 
0
  #4
Apr 26th, 2009
Kinger,

Here are three ways to do what you want using HTML and JavaScript, involving a mixture of mouseover and click events to cause text to be displayed.

Paste all the following code into a new text file - eg. test.html - then browse in your browser.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Untitled</title>
  5. <style type="text/css">
  6. /* General styles */
  7. body { font-family:verdana,arial,helvetics,sans-serif; }
  8. h1 { margin:0; font-size:14pt;}
  9. h2 { margin:0; font-size:12pt; }
  10. .method { margin:30px 0; }
  11. p.note { margin:3px 0 0 0; font-size:8pt; }
  12. p.sig { margin:12px 0 0 0; font-size:14pt; font-style:italic; }
  13.  
  14. /* Styles for Method 1 */
  15. #altImageWrapper { margin:3px 0 0 0; }
  16. #altImageWrapper img { border:0; }
  17.  
  18. /* Styles for Method 2 */
  19. #imageWrapper { position:relative; margin:6px 0 0 0; }
  20. #imageWrapper img { border-width:0; }
  21. #imageWrapper .popUpTxt { position:absolute; display:none; padding:0px 3px; font-weight:bold; background-color:#FFFFFF; font-size:10pt; border:1px solid #999999; }/* Note: This causes all three text divs to be absolutely positioned and initially hidden */
  22. #imageWrapper #popUpTxt1 { left:30px; top:35px; color:#800868; }
  23. #imageWrapper #popUpTxt2 { left:78px; top:35px; color:#800868; }
  24. #imageWrapper #popUpTxt3 { left:170px; top:35px; color:#F09000; }
  25.  
  26. /* Styles for Method 3 */
  27. #imageWrapper2 { margin:6px 0 0 0; }
  28. #imageWrapper2 img { border:0; }
  29. #popUpTxtWrapper { margin:12px 0 0 0; width:120px; height:1.0em; font-size:14px; font-weight:bold; text-align:center; border:2px solid #999999; }
  30. </style>
  31.  
  32. <script language="JavaScript" type="text/javascript">
  33. //No JavaScript required for Method 1
  34.  
  35. //For Method 2
  36. function showHideTxt(n, b_show){
  37. if(!n) return false;
  38. b_show = (!b_show) ? false : true;
  39. var wrapper = (document.getElementById) ? document.getElementById('imageWrapper') : document.all.imageWrapper;
  40. for(var i=1; i<=3; i++){
  41. var txtWrapper = (document.getElementById) ? document.getElementById('popUpTxt'+i) : document.all['popUpTxt'+i];
  42. txtWrapper.style.display = (b_show && i==n) ? 'block' : 'none';
  43. }
  44. return false;
  45. }
  46.  
  47. //For Method 3
  48. function showTxt(n, txt, color){
  49. if(!n) return false;
  50. txt = (!txt) ? '- - - - -' : txt;
  51. color = (!color) ? '#000000' : color;
  52. var txtWrapper = (document.getElementById) ? document.getElementById('popUpTxtWrapper') : document.all['popUpTxtWrapper'];
  53. txtWrapper.innerHTML = txt;
  54. txtWrapper.style.color = color;
  55. return false;
  56. }
  57. </script>
  58. </head>
  59.  
  60. <body>
  61. <h1>Show/hide text in response to User Events with an Image</h1>
  62. <p class="note">Three methods. In each method there is a "hot-spot" over the "D", "N" and "B" of <b>Daniweb</b>.</p>
  63.  
  64. <div class="method">
  65. <h2>Method 1: Imagemap with "alt" Text</h2>
  66. <p class="note">Place <b>mouse over</b> hot-spot to show text; move <b>mouse off</b> hot-spot to hide.</p>
  67. <p class="note">This is the easiest method by far as it involves only HTML, no Javascript.</p>
  68. <div id="altImageWrapper" class="method">
  69. <img src="http://www.daniweb.com/alphaimages/logo/logo.gif" useMap="#altTxt" />
  70. </div>
  71. <map name="altTxt">
  72. <area shape="rect" coords="30,0,58,30" href="" alt="D D D D D" onclick="this.blur(); return false">
  73. <area shape="rect" coords="78,0,106,30" href="" alt="N N N N N" onclick="this.blur(); return false">
  74. <area shape="rect" coords="170,0,195,30" href="" alt="B B B B B" onclick="this.blur(); return false">
  75. </map>
  76. </div>
  77.  
  78. <div class="method">
  79. <h2>Method 2: Imagemap with DHTML (text over image)</h2>
  80. <p class="note"><b>Click</b> hot-spot to show text; move <b>mouse off</b> hot-spot to hide.</p>
  81. <p class="note">Text written directly into HTML divs; text colors defined in CSS</p>
  82. <div id="imageWrapper">
  83. <img src="http://www.daniweb.com/alphaimages/logo/logo.gif" useMap="#dhtmlTxt1" />
  84. <div id="popUpTxt1" class="popUpTxt">D D D D D</div>
  85. <div id="popUpTxt2" class="popUpTxt">N N N N N</div>
  86. <div id="popUpTxt3" class="popUpTxt">B B B B B</div>
  87. </div>
  88. <map name="dhtmlTxt1">
  89. <area shape="rect" coords="30,0,58,30" href="" onclick="return showHideTxt(1, true)" onMouseOut="return showHideTxt(1, false)">
  90. <area shape="rect" coords="78,0,106,30" href="" onclick="return showHideTxt(2, true)" onMouseOut="return showHideTxt(2, false)">
  91. <area shape="rect" coords="170,0,195,30" href="" onclick="return showHideTxt(3, true)" onMouseOut="return showHideTxt(3, false)">
  92. </map>
  93. </div>
  94.  
  95. <div class="method">
  96. <h2>Method 3: Imagemap with DHTML (text outside image)</h2>
  97. <p class="note">Place <b>mouse over</b> hot-spot to show text; move <b>mouse off</b> hot-spot to hide.</p>
  98. <p class="note">Text and text color determined dynamically in event handler calls</p>
  99. <div id="imageWrapper2">
  100. <img src="http://www.daniweb.com/alphaimages/logo/logo.gif" useMap="#dhtmlTxt2" />
  101. </div>
  102. <div id="popUpTxtWrapper">- - - - -</div>
  103. <map name="dhtmlTxt2">
  104. <area shape="rect" coords="30,0,58,30" href="" onmouseover="this.blur(); return showTxt(1, 'D D D D D', '#800868')" onMouseOut="return showTxt(1, '')" onclick="this.blur(); return false">
  105. <area shape="rect" coords="78,0,106,30" href="" onmouseover="this.blur(); return showTxt(2, 'N N N N N', '#800868')" onMouseOut="return showTxt(2, '')" onclick="this.blur(); return false">
  106. <area shape="rect" coords="170,0,195,30" href="" onmouseover="this.blur(); return showTxt(3, 'B B B B B', '#F09000')" onMouseOut="return showTxt(3, '')" onclick="this.blur(); return false">
  107. </map>
  108. </div>
  109.  
  110. <p class="note">It shoud be fairly easy to mix and match methods 2 and 3 as necessary for the desired effect.</p>
  111. <p class="sig">Airshow</p>
  112.  
  113. </body>
  114. </html>
Personally I would say that an Applet would be a sledgehammer-to-crack-a-nut but, there again, I am not an Applet person.

Airshow
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,349
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 163
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: Simple Javascript Graphics

 
0
  #5
Apr 26th, 2009
W3 image map
  1. <img src="image.jpg" width="145" height="126" alt="image" usemap="#map" />
  2. <map name="map">
  3. <area shape="rect" coords="0,0,82,126" href="1.htm" alt="1" onclick onmouseover onmouseout ondblclick />
  4. <area shape="circle" coords="90,58,3" href="2.htm" alt="2" />
  5. <area shape="circle" coords="124,58,8" href="3.htm" alt="3" />
  6. </map>
Last edited by almostbob; Apr 26th, 2009 at 11:09 am.
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC