简体   繁体   English

Jquery在悬停时淡出背景?

[英]Jquery fade background on hover?

There is a link, with no background, and a css rule, which changes background on hover. 有一个没有背景的链接和一个css规则,它会在悬停时更改背景。

Parent bg is white, link on hover - blue. 父bg是白色的,悬停链接 - 蓝色。

How can I do a hover effect slowly , from white to blue? 如何从白色到蓝色缓慢地做悬停效果

Thanks. 谢谢。

li a {}
li a:hover { background: blue; }
jQuery('a#theLink').hover(function(){
    $(this).stop().animate({backgroundColor: 'blue'});
}, function() {
    $(this).stop().animate({backgroundColor: 'white'});
});

For this to work you need to download the " color plugin " for jQuery. 为此,您需要下载jQuery的“ 颜色插件 ”。

You don't need an extra color plugin. 您不需要额外的颜色插件。 You just need jQuery UI on top of jQuery, which lets you do animations also on color. 你只需要在jQuery之上使用jQuery UI,它也可以让你在颜色上做动画。 (Or if you don't want to use jQuery UI for some reason, I guess another plugin will do the trick. But I have successfully tried this with just including jQuery core and jQuery UI.) (或者,如果你不想出于某种原因使用jQuery UI,我想另一个插件就可以了。但是我已经成功地尝试了这个,只包括jQuery核心和jQuery UI。)

Animation itself goes something like... 动画本身就像......

$("li").hover(function() {
  $(this).animate({
    backgroundColor: "#ffffff"
  }, 'slow');
});

bgFade a very great and simple plugin that animates de background image: bgFade一个非常棒的简单插件,动画de background image:

http://www.isthatclear.com/jquery/bgFade/ http://www.isthatclear.com/jquery/bgFade/

为了动画颜色,您需要颜色插件

You'll need to use a plugin as JQuery can't animate colours out of the box. 你需要使用一个插件,因为JQuery不能开箱即用。

Try the Colour Animation plugin 试试Color Animation插件

Then it'll be something like: 然后它会是这样的:

$(this).animate({ backgroundColor: "blue" }, 'slow');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM