Img hover event flashing, imghover event flashing

Source: Internet
Author: User

Img hover event flashing, imghover event flashing

Today, I wrote a Photo Album photo to show the details with the mouse floating. When I encountered a flash bug and solved it smoothly, I wrote it down and shared it with you.

I am using the 'label: hover + tag' format. If you use events such as jquery mouseover and mouseout, you can also refer to this method. The principle is the same.

Analysis: The image is used, and then the div + span is used to write the text and background to be displayed with the mouse floating. Code as follows: (flashing will occur)

Html code:

1  2 <div> 3 <span> image 1 </span> 4 <span> name </span> 5 </div>

Css code:

1*{2 margin: 0; 3 padding: 0; 4} 5 img, div {/* Note that the image and div size must be consistent, and the position must overlap */6 width: 200px; 7 height: 200px; 8} 9 div {/* after the div position is set, set it to hide */10 background-color: rgba (242,242,242, 0.7); 11 position: absolute; 12 margin-top:-203px; 13 display: none; 14} 15/* bug position */16 img: hover + div {/* move the cursor to img, change the display style of the following div to display block */17 display: block; 18 cursor: pointer; 19} 20 span {21 display: inline-block; 22 margin-bottom: 15px; 23 margin-left: 70px; 24} 25 span: nth-of-type (1) {26 margin-top: 50px; 27}

Think about the mouse floating process. When you move the mouse over img, The div is displayed. However, after the div is displayed, although the Mouse looks inside the image area, however, the element of the mouse hover has become the div that appears, so at this time, the div will continue to return to display: none;, and the cycle will continue to flash.
Therefore, add a style, that is, move the mouse to the div, and modify the display style of the div to block. You can directly add the Code with the bug location (Add ', div: hover'). The Code is as follows:

img:hover + div, div : hover{  display: block;  cursor: pointer;}

In this way, the photo floating effect is perfect ~

If any error occurs, please correct it!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.