JavaScript
  Home arrow JavaScript arrow Page 3 - Creating Pop-up Notes with CSS and JavaScr...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Creating Pop-up Notes with CSS and JavaScript Part II
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 24
    2005-01-24

    Table of Contents:
  • Creating Pop-up Notes with CSS and JavaScript Part II
  • The HTML markup
  • The complete code
  • Summary

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating Pop-up Notes with CSS and JavaScript Part II - The complete code


    (Page 3 of 4 )

    As seen previously, one possible improvement for the script is to replace the "onmouseover" event handler with "onmousemove," and achieving the "chasing" note effect. It’s up to you decide how the notes will be displayed.

    As usual, the complete code is listed below:

    <html>
    <head>
    <title>MULTIPLE POP-UP NOTES</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <script language="javascript">

    createNotes=function(){

                showNote=function(){
                            // gets corresponding note element id
                            var id=this.id.replace(/a/,'note');
                            note=document.getElementById(id);
                            // assigns X,Y mouse coordinates to note element
                            note.style.left=event.clientX;
                            note.style.top=event.clientY;
                            // makes note element visible
                            note.style.visibility='visible';
                }

                hideNote=function(){ 
                            // gets corresponding id for note element
                            var id=this.id.replace(/a/,'note');
                            note=document.getElementById(id);
                            // hides note element
                            note.style.visibility='hidden';
                }

                // gets all <a> elements 
                as=document.getElementsByTagName('a');
                // iterates over all <a> elements
                for(i=0;i<as.length;i++){
                            // assigns mouse event handlers to <a> elements with class name "special"
                            if(/\bspecial\b/.test(as[i].className)){
                                        // shows note element when mouse is over 
                                        as[i].onmousemove=showNote;
                                        // hides note element when mouse is out
                                        as[i].onmouseout=hideNote;
                            }
                }
    }

    // execute code once page is loaded
    window.onload=createNotes;
    </script>

    <style type="text/css">

    p {
                font: normal 11px "Verdana", Arial, Helvetica, sans-serif;
                color: #000;
    }

    a.special:link,a.special:visited {
                font: bold 11px "Verdana", Arial, Helvetica, sans-serif;
                color: #00f;
                text-decoration: underline;
    }

    a.special:hover {
                color: #f00;
    }

    .note {
                position: absolute; 
                top: 0px;
                left: 0px;
                background: #ffc;
                padding: 10px;
                border: 1px solid #000;
                z-index: 1;
                visibility: hidden;
                font: bold 11px "Verdana", Arial, Helvetica, sans-serif;
                color: #000;
    }

    </style>
    </head>
    <body>

    <p>For web development, <a href="#" id="a1" class="special">PHP</a> is just great.</p>

    <div id="note1" class="note">PHP: PHP Hypertext Preprocessor</div>

    <p><a href="#" id="a2" class="special">SQL</a> is the standard language for querying databases.</p>

    <div id="note2" class="note">SQL: Structured Query Language</div>

    <p>In fact <a href="#" id="a3" class="special">DHTML</a>, is a fusion of HTML and client-side programming.</p>

    <div id="note3" class="note">DHTML: Dynamic Hypertext Markup Language</div>

    </body>
    </html>

    The visual output for the code is illustrated with the following images:

    And that’s it. We now have a script that works the way we want.

    More JavaScript Articles
    More By Alejandro Gervasio


       ·  Here's the second part of the article. We're dealing with creating multiple...
       · I'm confused as to why you've used visibility:hidden; instead of...
       ·  That's right. Visibiliy simply hides the element without removing it from the...
       · The notes stay visible in Safari (1.2.4) when using onmousemove - changing to...
       ·  Yes,I've tried with Firefox, but it doesn't handle properly the event object when a...
       · Error: event is not definedSource File:...
       · Hi,I was unable to acces your provided URL.Alejandro Gervasio
       · As the code is it does not work with Firefox. It did, however, work properly with...
       · Hi Alejandro,Great article. From it, I figured out 2 things:1) simpler way...
       · Hi thereI have tried this with long pages. The pop-up notes work in the top part...
       · Hello,Thank for your comments on this article. With reference to your question,...
       · Hello,Thanks for the comments. Regarding your question, here's a modified...
       · Thank you very much AlejandroI used some bits of your code along with info from...
       · Hello again,Thank you for posting your message. I'm glad to hear that you found...
       · Even with this modified code, I still see the same problem. The pops aren't visible...
       · Thank you for your feedback. I changed the function I posted before, in order to...
       · Hi, I am trying to get multiple pop-up notes to appear when I click on an image...
       · Thanks for commenting on my JavaScript article. Concerning your question, this...
       · good day..it is still not working in firefox, is there already any fix script on...
     

    JAVASCRIPT ARTICLES

    - Using jQuery to Preload Images with CSS and ...
    - Using Client-Side Scripting to Preload Image...
    - Removing Non-Semantic Markup when Preloading...
    - Using the Display CSS Property to Preload Im...
    - Preloading Images with CSS and JavaScript
    - Scaling and Moving Web Page Elements with th...
    - Fading, Hiding and Sliding HTML Elements wit...
    - Toggling CSS Properties with the GX JavaScri...
    - Cancel, Queue and Pause Animations with the ...
    - Producing Elastic Effects with the GX JavaSc...
    - Moving Divs Diagonally with the GX JavaScrip...
    - Moving Elements Vertically and Horizontally ...
    - Making Bouncing Effects in Parallel with the...
    - Creating Bouncing Effects with the GX JavaSc...
    - Manipulating Background Colors with the GX J...







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek