jQuery: hover() method
Giải phóng thời gian, khai phóng năng lực
Phương thức hover() sẽ thực hiện hai công việc tương đương với thực hiện hai phương thức mouseenter() và mouseleave().
Cú pháp:
Bộ_chọn.hover(function(){
Khối_lệnh_mouseenter;
}, function(){
Khối_lệnh_mouseleave;
});
Ví dụ:
<!DOCTYPE html> <html> <head> <title>hover()</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <section id="s1" style="width: 480px;height: 360px;background: red"></section> <script> $("#s1").hover( function(){$(this).css("opacity","0.5");}, function(){$(this).css("opacity","1");} ); </script> </body> </html>
Giải phóng thời gian, khai phóng năng lực