如何使用 jQuery 在滑鼠懸浮時為背景顏色新增動畫變化?
要更改背景顏色,請使用 mouseenter 事件。當你將滑鼠游標懸停在上面時,背景顏色就會變化
mouseenter: function(){
$(this).css("background-color", "gray");
}滑鼠游標懸停在以下元素上
<p class="my">Click and move the mouse pointer to change the background color.</p>
你可以嘗試執行以下程式碼來學習如何在滑鼠懸停時為背景顏色新增動畫變化
舉例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("body").on({
mouseenter: function(){
$(this).css("background-color", "gray");
},
mouseleave: function(){
$(this).css("background-color", "red");
},
});
});
</script>
</head>
<body>
<p class="my">Click and move the mouse pointer to change the background color.</p>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP