javascript - jQuery 动画/悬停和淡入淡出

标签 javascript jquery html

这是我的index.html


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css" media="all">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="fade.js"></script>
</head>

<body> <div id="wrapper"> <div id="header"></div> <div class="spacer"></div> <div class="nav"> <a>&nbsp;</a> <a href="" class="nav_menu" title="HOME">HOME</a> <a href="" class="nav_menu" title="PORTFOLIO">PORTFOLIO</a> <a href="" class="nav_menu" title="ABOUT ME">ABOUT ME</a> <div class="clearer"></div> </div> </div> </body> </html>

I wanted to fade the navigation menu to an image that I made.

and this is my fade.js that is working.


$(document).ready(function(){
  $("a.nav_menu").hover(
    function() {
      $(this).stop().animate({"opacity": "0"}, "slow");
    },
    function() {
      $(this).stop().animate({"opacity": "1"}, "slow");
    });
});

我已经试过了。但它不起作用。


$(function(){
  $("a.nav_menu")
    .mouseover(function(){
      $(this).stop().animate({'background-image':'url(nav_hover.jpg)'},3000);
    })
    .mouseout(function(){
      $(this).stop().animate({'background-image':'url(nav_.jpg)'},3000);
    })
});

谁能帮帮我。

最佳答案

看看这篇博文:http://www.bendewey.com/blog/index.php/9/jquery-rollover-image

根据 Daniel Roberts 的回答,该插件类似于他的解决方案#2,我在底部建立一个带有图像的基本链接,然后使用相对定位,将悬停图像放在顶部。当用户将鼠标悬停在链接上时,顶部的悬停图像会从不透明度 0 变为 1,现在根据背景中的图像,这可能看起来不错且无缝,但是,如果您的背景图像具有很大的对比度,结果可能会有有趣的结果。

关于javascript - jQuery 动画/悬停和淡入淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1996320/

相关文章:

html - 如何用段落填充div高度?

javascript - 如何在 JavaScript 中检测 native 浏览器/引擎对象

javascript - 复选框上的事件未发生

javascript - ng-model 进入文本区域不会更新

javascript - 如何使用播放、暂停、重置功能控制多段线上的符号(使用 Google Map API)

javascript - 选择标签、替换值 (JavaScript)

Jinja "for"循环中的 Javascript

javascript - 通过 JavaScript 设置文件输入的值会触发看似无关的事件

javascript - 使用 jquery 显示有限的数据

javascript 文档就绪一遍又一遍地触发