這篇文章主要介紹了基于jQuery創(chuàng)建鼠標(biāo)懸停效果的方法,實(shí)例分析了jQuery實(shí)現(xiàn)鼠標(biāo)特效的原理與詳細(xì)步驟,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
本文實(shí)例講述了基于jQuery創(chuàng)建鼠標(biāo)懸停效果的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
1. 創(chuàng)建HTML:
- <ul>
- <li><a href="/tv"><img src="images/tv_off.gif" class="mainnav"></a></li>
- </ul>
2. 選擇.mainnav的class:
- $(".mainnav").hover(
- function () {
- },
- function () {
- }
- );
3. 建立變量imgPath,指定圖片SRC:
- $(".mainnav").hover(
- function () {
- // Grab the source
- var imgPath = $(this).attr("src");
- },
- function () {
- // Grab the source
- var imgPath = $(this).attr("src");
- }
- );
4. 找到字符串off,用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"));
- }
- );
希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選