使用jQuery淡入背景色? [英] Fade in background color using jQuery?

查看:95
本文介绍了使用jQuery淡入背景色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想进行一个div设置,然后在mouseenter上将背景淡化为白色,在mouseout上将背景淡化为黑色.关于如何在jQuery中执行此操作的任何想法?

I would like to take a div and have the background fade to white on mouseenter and fade back out to black on mouseout. Any ideas on how to do this in jQuery?

推荐答案

  $("div" ).hover(
  function() {
     $(this).animate({backgroundColor: "#fff"}, 'slow');
  }, function() {
    $(this).animate({backgroundColor:"#000"},'slow');
  });

使用JQuery .mouseover()

with JQuery .mouseover()

$("div")
  .mouseover(function() {
    $(this).animate({backgroundColor: "#fff"}, 'slow');
  })
  .mouseout(function() {
    $(this).animate({backgroundColor:"#000"},'slow');
  });

注意,您必须使用jquery-color(用于设置颜色动画). https://github.com/jquery/jquery-color/

Note you have to use jquery-color (for animating colors). https://github.com/jquery/jquery-color/

这篇关于使用jQuery淡入背景色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆