V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
jerichowon
V2EX  ›  问与答

请教一个关于JQuery动画效果的问题。

  •  
  •   jerichowon · 2012-01-16 12:58:28 +08:00 · 3420 次点击
    这是一个创建于 4496 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我想实现一种效果:鼠标进入Div的时候Div背景色变色,代码我写成下面的样子:
    $("#DivId").hover(function () {
    $(this).animate({ backgroundColor: "#000"}, 500);
    },
    function () {
    $(this).animate({ backgroundColor: "#fff"}, 500);
    });

    可是运行以后没有效果- -!!

    我查看其他网站js代码后发现有些网站也是这么写的,效果就很好。

    请教一下大家到底是哪里出问题了?
    6 条回复    1970-01-01 08:00:00 +08:00
    issac
        1
    issac  
       2012-01-16 13:02:50 +08:00
    css:
    div {background-color:#fff;}
    div:hover {background-color:#000;}
    cmonday
        2
    cmonday  
       2012-01-16 13:35:56 +08:00
    jQuery 的 animate 方法自身并不支持颜色。请参考这里的答案:
    http://stackoverflow.com/questions/190560/jquery-animate-backgroundcolor
    frittle
        3
    frittle  
       2012-01-16 13:47:58 +08:00
    需要jQuery UI库,或者这个相对来说小很多的jQuery插件
    https://github.com/jquery/jquery-color

    详细的楼上那个链接里也说明了。
    jerichowon
        4
    jerichowon  
    OP
       2012-01-16 14:00:46 +08:00
    发现了,要引入一个jquery.effect.core.js的文件,然后渐变效果就有了。
    icyflash
        5
    icyflash  
       2012-01-16 15:05:33 +08:00
    jerichowon
        6
    jerichowon  
    OP
       2012-01-17 21:55:10 +08:00
    @icyflash 打算学一下css3了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3320 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 13:30 · PVG 21:30 · LAX 06:30 · JFK 09:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.