Home > Web Front-end > JS Tutorial > Method to create mouseover effect based on jQuery_jquery

Method to create mouseover effect based on jQuery_jquery

WBOY
Release: 2016-05-16 16:11:02
Original
1447 people have browsed it

The example in this article describes how to create a mouse hover effect based on jQuery. Share it with everyone for your reference. The specific implementation method is as follows:

1. Create HTML:

<ul>
<li><a href="/tv"><img src="images/tv_off.gif" class="mainnav"></a></li>
</ul>
Copy after login

2. Select the class of .mainnav:

$(".mainnav").hover(
 function () {
 },
 function () {
 }
);
Copy after login

3. Create variable imgPath and specify image SRC:

$(".mainnav").hover(
 function () {
  // Grab the source
  var imgPath = $(this).attr("src");
 },
 function () {
  // Grab the source
  var imgPath = $(this).attr("src");
  }
);
Copy after login

4. Find the string off and replace it with on:

$(".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"));
  }
);
Copy after login

I hope this article will be helpful to everyone’s jQuery programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template