classMouseHover: Cosmetic Mouse Interaction
When the mouse moves over a button, link or menu-item, some highlighting is expected to indicate its interactivity. The javascript involved however is anything but straight forward to implement in an orderly way.
This script simplifies the process to a single class name.
Highlighting Images
Images that highlight have been around for so long, that any user is familiar with having a button light up when the mouse is moved over it. It's a very common way to indicate that an element is inviting interactivity. Below are several examples of achieving a highlighting effect.
Cached Image Replacing
Replacing the image with a highlighted version is the oldest and most reliable way. Implementing it in this way, limits the effort to adding a class-name. Move the mouse pointer over the images below to see the script replace the grey version of the images with a pre-loaded coloured one.
Fading Image Hovers
This is a slightly more decorative method. The highlighted version of the image is faded in over the grey version.
This method is more delicate as the highlighted version needs to be positioned accurately. The script might not be able to do this in all layout situations.
Table Rows
Highlights aren't limited to buttons, links and images. Below the table's rows highlight under the mouse.
| Icon | Description |
|---|---|
| Total: | 11 |
![]() |
Bigger |
![]() |
Copy |
![]() |
Create Link |
![]() |
Delete |
![]() |
Insert Image |
![]() |
Insert |
![]() |
Paste |
![]() |
Toggle HTML |
![]() |
Toggle Text |
![]() |
Undo |
![]() |
Unlink |
Making the whole row clickable is achieved using another classbehaviour classname. "clickOnParent parent_2" Moves the functionality from the link to the entire table row.
Tool-tip Explanations
The example below shows the complexity a simple hover effect can achieve. The tooltip requires no script at all, except in Internet Explorer 6.
-
Bigger
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
-
Copy
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
-
Create Link
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
-
Delete
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
-
Insert Image
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
-
Insert
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
-
Paste
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
-
Toggle HTML
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
-
Toggle Text
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
-
Undo
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
-
Unlink
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
The "Folding Menu" is an even more complex example of using a hover effect.
Required Files
-
jQuery Addon Script: jquery.classbehaviours.classmousehover.js
- Optional Script: jquery.classbehaviours.srcmousehover.js
- Optional Script: jquery.classbehaviours.fademousehover.js
- Prerequisite Script: jquery.classbehaviours.js
- Example Markup: classMouseHover.html
- Example Stylesheet: classMouseHover.css
Comments on this Article