JQuery's hover method works with css's hover selector to highlight selected elements. jqueryhover
Problem description:
Today, I met the following requirement to help my sister develop a webpage:
Do not move the mouse to the table. The transparency of the table remains unchanged.
Move the cursor to the table, and the transparency of the hover to cells remains unchanged.
Paste the results I have achieved. At first, the table transparency remains unchanged.
When I move the cursor to the third cell in the second row, other cells decrease the transparency.
Solution
At first, I used the CSS implementation method, as shown below:
#table td{ opacity:0.5;}#table td:hover{ opacity:1;}
However, at the beginning, the table transparency is 0.5, which looks bad.
Later, I used the hover method of jQuery, but it always selects all the cells in it. The process is tortuous and I will not introduce them one by one. I will explain how to implement it.
$('#content td').hover( function(){ $('#content td').css('opacity','0.5'); $('#content td:hover').css('opacity','1'); }, function(){ $('#content td').css('opacity','1'); });
Content is the id of my table. We can see that two functions are added to the cell hover method.
When the first funtion is moved to the table
$('#content td').css('opacity','1');
Indicates that when the mouse moves in, the transparency of all cells is 0.5, and then
$('#content td:hover').css('opacity','1');
The hover selector of css indicates selecting a single cell.
The second funtion indicates that when the mouse leaves the table