On the Web page always see this effect: put the mouse into a small lattice, small lattice darkened, while showing some text. has been more curious, today I also simple to achieve a bit, if there is no wrong or better way, please advise.
The general idea is to build a new div that overwrites the image and displays the word, the div is displayed when the mouse moves to the IMG, and the div disappears when you move out of IMG.
1. Build a basic page:
<div id= "Ten_model" > <ul id= "Little_imgs" > <li id= "li1" ></li> id= "Li2" ></li> <li id=" Li3 "></li> <li id= "Li4" ></li> <li id=" li5 "></li> < Li id= "li6" ></li> <li id= "li7" ></li> <li id= "li8" ></li> <li id= "Li9" ></li> <li id=" li0 "></li> </ul></div>
The above is the 10 basic image of the HTML code, put into a UL inside.
1 Ul#little_imgs{2 List-style:None;3 position:relative;4 width:300px;5 Height:Auto;6}7 8 Ul#little_imgs Li{9 width:120px;Ten Height:120px; One float: Left; A margin:3px; -}
The above is for the UL and Li css decoration, let it every two lines, a total of five rows of two columns.
<div id= "Show_model" > <p></p></div>
Div#show_model { width:120px; height:120px; Background-color:black; Opacity:. 7; Position:absolute; left:0; top:0; Display:none;}
The above is the div shown on Li when the mouse moves to each Li, with the aim of darkening the effect (implemented via opacity) and text display (<p></p>).
2. Add JavaScript Effect:
$ ("#little_imgs li"). MouseOver (function () {var LL = $ (this). Offset (). var TT = $ (this). Offset (). Top; $ ("#show_model"). CSS ("left", Ll-2); $ ("#show_model"). CSS ("top", tt-2); var li_id = $ (this). attr ("id"); if (li_id = = ' Li1 ') {$ ("#show_model p"). HTML ("L"); }else if (li_id = = ' Li2 ') {$ ("#show_model p"). html ("O"); }else if (li_id = = ' Li3 ') {$ ("#show_model p"). HTML ("A"); }else if (li_id = = ' Li4 ') {$ ("#show_model p"). HTML ("B"); }else if (li_id = = ' Li5 ') {$ ("#show_model p"). HTML ("N"); }else if (li_id = = ' Li6 ') {$ ("#show_model p"). html ("Li"); }else if (li_id = = ' Li7 ') {$ ("#show_model p"). HTML ("D"); }else if (li_id = = ' Li8 ') {$ ("#show_model p"). HTML ("Na"); }else if (li_id = = ' Li9 ') {$ ("#show_model p"). HTML ("Ra"); }else if (li_id = = ' Li0 ') {$ ("#show_model p"). HTML ("RB"); } $ ("#show_model"). CSS ("Display", "block"); }); $ ("#show_model"). MouseOver (function () {$ (this). CSS ("Display", "block"); }); $ ("#show_model"). Mouseout (function () {$ (this). CSS ("display", "none"); }); $ ("#ten_model"). Mouseout (function () {$ ("#show_model"). CSS ("display", "none"); });
Using jquery, when the mouse moves to each Li, get the top and height of Li, and assign value to Show_model, and give Show_model p value text, let it display, the problem is that the first layer of the overlay will keep flashing, Later analysis found: When the mouse moved to Li, will show Show_model div but at this time the mouse has left Li, so the Show_model div will disappear, once disappeared, the mouse fell on Li, so the Show_model Div will show up again, So reciprocating. The solution is to add the Show_model div to the MouseOver event and, when on top of it, the div will not disappear.
The basic implementation of the scene, if you want to add the click event to the IMG image, because there is a block of Div, there will be an impact, the solution is: the Click event is divided into two parts, MouseDown when the div disappears, MouseUp add img Image of the original click event.
Move the mouse over the picture to display the relevant information