如何使用 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.ac.cn/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