2012-07-26 170 views
0

这是我正在处理的页面:http://dsa.dartmouth.edu/。幻灯片下面是四个面板,可以在悬停时更改颜色。背景颜色工作正常,但标题颜色在变成白色后从未回到其黑色。下面是控制这个的javascript - 我怎样才能让h2文本在转出时变回黑色?除非你有jQuery UIJquery淡入淡出问题

$featured_control_item.hover(function(){ 
     if (! $(this).hasClass('active-slide')){ 
      $(this).find('.et_slide_hover').css({'display':'block','opacity':'0'}).stop(true,true).animate({ 'opacity' : '1' }, featured_controllers_opacity_speed); 
      $(this).find('.controller').find('h2').css({'color':'white'}).stop(true,true).animate({ 'color' : '#656464' }, featured_controllers_opacity_speed); 
     }}, function(){ 
     $(this).find('.et_slide_hover').stop(true,true).animate({ 'opacity' : '0' }, featured_controllers_opacity_speed); 
     $(this).find('.controller').find('h2').stop(true,true).animate({ 'color' : '#656464' }, featured_controllers_opacity_speed); 
    }); 

回答

1

你不能动画的颜色变化,所以也许尝试:

$featured_control_item.hover(function(){ 
    if (!$(this).hasClass('active-slide')) 
    { 
    $(this).find('.et_slide_hover').css({'display':'block','opacity':'0'}).stop(true,true).animate({'opacity' : '1'}, featured_controllers_opacity_speed); 
    $(this).find('.controller').find('h2').stop(true,true).css({'color' : 'white'}); 
    }}, function(){ 
    $(this).find('.et_slide_hover').stop(true,true).animate({ 'opacity' : '0' }, featured_controllers_opacity_speed); 
    $(this).find('.controller').find('h2').stop(true,true).css({'color' : '#656464'}); 
}); 
0

jQuery的.animate()不做颜色。所以下载并包含jQueryUI JS文件(将其包含在jquery.js之后),或者将代码更改为仅使用.css()

1

您的问题是jQuery animate功能不允许动画颜色。你将不得不使用一个单独的插件。

所有动画处理的属性应该被动画化以单一数值, 除了下面提到;那些非数字不能使用基本功能的jQuery被动画 最属性(例如,宽度,高度, 或左可以是动画,但背景颜色不能,除非使用 jQuery.Color()插件)。除非另有说明,否则将属性值视为 像素数。在适用的情况下,单位em和%可以是 。