我是靠谱客的博主 大力蜜蜂,这篇文章主要介绍基于jQuery创建鼠标悬停效果的方法,现在分享给大家,希望可以做个参考。

本文实例讲述了基于jQuery创建鼠标悬停效果的方法。分享给大家供大家参考。具体实现方法如下:

1. 创建HTML:

复制代码
1
2
3
<ul> <li><a href="/tv"><img src="images/tv_off.gif" class="mainnav"></a></li> </ul>

2. 选择.mainnav的class:

复制代码
1
2
3
4
5
6
$(".mainnav").hover( function () { }, function () { } );

3. 建立变量imgPath,指定图片SRC:

复制代码
1
2
3
4
5
6
7
8
9
10
$(".mainnav").hover( function () { // Grab the source var imgPath = $(this).attr("src"); }, function () { // Grab the source var imgPath = $(this).attr("src"); } );

4. 找到字符串off,用on替换:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$(".mainnav").hover( function () { // Grab the source var imgPath = $(this).attr("src"); // Replace the path in the source $(this).attr("src",imgPath.replace("off", "on")); }, function () { // Grab the source var imgPath = $(this).attr("src"); // Replace the path in the source $(this).attr("src",imgPath.replace("on", "off")); } );

希望本文所述对大家的jQuery程序设计有所帮助。

最后

以上就是大力蜜蜂最近收集整理的关于基于jQuery创建鼠标悬停效果的方法的全部内容,更多相关基于jQuery创建鼠标悬停效果内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(149)

评论列表共有 0 条评论

立即
投稿
返回
顶部