简体   繁体   English

Jquery淡出淡出问题

[英]Jquery fade in fade out issue

Here is the page I'm working on: http://dsa.dartmouth.edu/ . 这是我正在处理的页面: http//dsa.dartmouth.edu/ Below the slideshow are four panels that change colors on hover. 幻灯片下方是四个面板,可在悬停时更改颜色。 The background color works fine, but the title color never turns back to its dark color after turning white. 背景颜色工作正常,但标题颜色在变为白色后永远不会变回其深色。 Below is the javascript controlling this - how can I get the h2 text to change back to a dark color on rollout? 下面是控制它的javascript - 如何在推出时让h2文本更改为深色?

$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 );
    } );

Your problem is that the jQuery animate functionality does not allow for animating colors. 您的问题是jQuery动画功能不允许动画颜色。 You will have to use a separate plugin for that. 你必须使用一个单独的插件。

All animated properties should be animated to a single numeric value, except as noted below; 除非如下所述,否则应将所有动画属性设置为单个数值。 most properties that are non-numeric cannot be animated using basic jQuery functionality (For example, width, height, or left can be animated but background-color cannot be, unless the jQuery.Color() plugin is used). 大多数非数字属性无法使用基本jQuery功能进行动画处理 (例如,宽度,高度或左边可以设置动画,但背景颜色不能,除非使用jQuery.Color()插件)。 Property values are treated as a number of pixels unless otherwise specified. 除非另有说明,否则属性值被视为多个像素。 The units em and % can be specified where applicable. 可以在适用的情况下指定单位em和%。

You cant animate an color change, so maybe try: 你不能为颜色变化设置动画,所以也许试试:

$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'});
});

jQuery .animate() doesn't do colours unless you include jQuery UI too. 除非你也包含jQuery UI,否则jQuery .animate()不会执行颜色。 So download and include the jQueryUI JS file (include it after jquery.js), or change your code to just use .css() . 因此,下载并包含jQueryUI JS文件(在jquery.js之后包含它),或者将代码更改为仅使用.css()

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

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