【问题标题】:JQuery .animate() not working with ReactJS?JQuery .animate() 不能与 ReactJS 一起使用?
【发布时间】:2015-09-04 07:31:34
【问题描述】:

当用户使用 jQuery .animate() 点击单元格时,我试图突出显示该单元格

clickHandler: function() {

var cell = React.findDOMNode(this.refs.cell);

// $(cell).css("background-color", "blue"); // THIS WORK


$(cell).animate({

  backgroundColor: "blue"

}, 1000); // THIS DOESN'T WORK

},

我也在使用 React.addons.CSSTransitionGroup。可能 jQuery .animate 和它有冲突。

感谢您的帮助。

【问题讨论】:

标签: jquery reactjs


【解决方案1】:

看看这个页面提示http://www.w3schools.com/jquery/eff_animate.asp 在参数样式下,描述

TIp 核心 jQuery 库中不包含彩色动画。如果你想要动画颜色,你需要从 jQuery.com 下载 Color Animations 插件

您必须下载并包含 color animate 插件才能执行此操作。 这是一个链接:http://plugins.jquery.com/color/供下载。

【讨论】:

    【解决方案2】:

    如果您不需要对 IE9 的支持,所有其他浏览器都支持过渡。

    CSS:

    .my-color-element { background-color: blue; transition: background-color .4s linear }
    .my-color-element.transition { background-color: red; }
    

    JS:

    clickHandler: function() {
    
      var cell = React.findDOMNode(this.refs.cell);
      $(cell).addClass('transition');
    
    },
    

    http://caniuse.com/#search=transition

    【讨论】:

    • 感谢您的帮助!事实上 jQuery 动画确实适用于 reactJS,但你需要导入 jQuery 颜色。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-22
    • 2021-05-09
    • 2020-01-28
    • 2018-01-23
    • 2016-03-23
    • 1970-01-01
    相关资源
    最近更新 更多