JavaScript
  Home arrow JavaScript arrow Page 4 - 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  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
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 I
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 47
    2005-01-19

    Table of Contents:
  • Creating Pop-Up Notes with CSS and JavaScript Part I
  • Creating static pop-up notes
  • Creating dynamic pop-up notes
  • The HTML markup

  • 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 I - The HTML markup


    (Page 4 of 4 )

    The HTML markup is almost identical, and is shown here:

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

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

    The full code for the page is as follows:

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

    <script language="javascript">

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

                hideNote=function(){
                            // gets note1 element
                            var note1=document.getElementById('note1');
                            // hides note1 element
                            note1.style.visibility='hidden';
                }

                var a1=document.getElementById('a1');
                // shows note1 element when mouse is over
                a1.onmouseover=showNote;
                // hides note element when mouse is out 
                a1.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;
    }

    #note1 {
                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">PHP: PHP Hypertext Preprocessor</div>

    </body>
    </html>

    The visual output is illustrated in the following images, indicating X - Y mouse coordinates:

    As we can appreciate from these screenshots, the pop-up note appears at the mouse coordinates, expanding the limits of the previous static example, and displaying a more polished look.

    If we wish improve the script even more, we might replace the "onmouseover" event handler with the "onmousemove" event handler within the code. Doing so, the note will be displayed "chasing" the mouse pointer, implementing an additional effect that can be potentially more appealing to visitors. All we have to do is replace the following line:

    a1.onmouseover=showNote;

    with this:

    a1.onmousemove=showNote;

    and that's all. We have a fully functional pop-up note that is very useful to include in our pages. Are we done? Not quite.

    Note that in its current from, this script doesn't scale very well, since we're manipulating a single pop-up note. We did this to simplify the script, just so it's easier to understand how the JavaScript code is manipulating CSS. The next logical step would be expanding out the limits of the script to handle any number of notes across the Web document, which is the goal initially intended. In Part 2, we'll cover the creation of multiple pop-up notes. 


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hello,The article explains in a detailed way, how to build pop-up notes using...
       · It's very useful for all to make web!Thank you!I will hope u post PartII.
       · Hi,Thank you for your feedback. Very much appreciatedAlejandro...
       · However the code is rather sloppy. You don't check for any availability of objects...
       · Thank you for the comment. You point is right, since the title attribute is good...
       · That might be the case, but where is the logical connection between the element and...
       · Yep, I've read carefully your above reasons, and they're pretty good. The whole...
       · This method is very bad from a semantics point of view. If you use a screen reader,...
       ·  Hi there, Thank you for your comments. Of course I agree that the title...
       · Hey,I would just look at the successful exposure, in a pedagogical sense.I...
       · Sure, it could work inserting images inside divs. Jut give a try.Thank you for...
       · There are plenty of occasions where this pop-up note could be useful and...
       · Hello friend,The suggested example is something that I haven't been thinking of,...
       · If you cut and paste the "here's the full code" bit you will find it works fine in...
       · Was it even mentioned? I didn't see anything discussing the compatibility issues. ...
       · Thank you for the good contributions here. As far I know, the script works in...
       · ok the scripts all good and all but what if you are new to css like me how and where...
       · Thank you for commenting on my article. Concerning your question, the tutorial...
     

    JAVASCRIPT ARTICLES

    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget
    - Ajax Hack for Entering Information Without R...
    - EXT JS 2.1 Overview
    - Using the Style Object for Zebra Tables with...
    - Binary Searching
    - An Improved Approach to Building Zebra Tables






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT