Thursday, November 9, 2006

Cool Mouse Over Effects
















Ever wanted to show a popup information window when the mouse rolls over an
image, a grid cell, a hyper link or any other UI control?


In this article we display a table (window) when the user rolls over an ASP.NET
server-side control.


The window to display is contained in a "div" tag. The content of the "div" tag
may be changed at runtime using the javascript "innerHtml" property. These will
be described later.


First, We need to define a style for the "div" tag. The style could be defined
within the html HEAD tags as follows:




Above position:absolute is necessary. The position of
the <div> tag will change as we move the mouse over different controls.
position:absolute position 
insures
the div will be positioned at the new location.


Next we define two javascript functions for showing and hiding the div:





Above the showimage() function will be called on the onmouseover event.
window.event.x and window.event.y specify the location of the mouse during the
onmouseover event.

The coordinates of the "div" will be set using the x, y mouse location. To the
mouse x location we simply add extra space so that the window will be displayed
a bit to the right of our control.


The content of the "div" is changed using the innerHTML attribute as follows:





Next, In the .ASPX file define your rollover div tag:



Next, we need to program our asp.net server side control to respond to
javascript client-side events. This would be done on the server side. For
example in C#:




Above we program our server control, MyServerControl1, to respond to the
client-side


onmouseover and onmouseout events. To the showimage function we pass strTitle
which is the text we want to display in the window. The info is displayed using
innerHTML attribute as described above.






Copyright @ Isaac Levy, Los Angeles, CA


(Author's Email: RisingDeepStar@yahoo.com)





No comments: