【问题标题】:JavaScript + CSS3 animations not working properly?JavaScript + CSS3 动画不能正常工作?
【发布时间】:2016-11-13 13:15:19
【问题描述】:

我目前正在编写一个名为 quickly.js 的库。有conceal(milliseconds) 和display() 函数,它们具有通过CSS 编程的动画。隐藏功能动画正常工作,但显示功能动画不能正常工作。它不会淡入。相反,它突然出现。这是一个演示错误的 JSFiddle:https://jsfiddle.net/v6esmqtf/6/。

【问题讨论】:

  • “无法正常工作”是什么意思?请具体说明您希望它做什么。
  • @discipline 更新问题
  • 你没有设置显示功能-jsfiddle.net/ypz7m241/

标签: javascript css animation


【解决方案1】:

您根本没有设置display 函数。

Element.prototype.conceal = function(ms) {
  ms = ms || 0;
  var thisStyle = this.style;
  thisStyle.opacity = 0;
  setTimeout(function() {
    thisStyle.display = "none";
  }, ms);
};

Element.prototype.display = function(ms) {
  ms = ms || 0;
  var thisStyle = this.style;
  thisStyle.display = "";
  setTimeout(function() {
    thisStyle.opacity = 1;
  }, ms);
};

然后……

document.getElementById("conceal").onclick = function() {
  document.getElementById("get").conceal(800);
};

document.getElementById("display").onclick = function() {
  document.getElementById("get").display(0);
};

希望这会有所帮助。

【讨论】:

  • 奇怪的是 setTimeout() 需要在那里,即使没有延迟。我将代码更改为在 display() 函数中没有参数。相反,我以零延迟运行 setTimeout()。
  • 我认为这是因为 opacity 有一个内置的关键帧时间 - 你可以使用 JQ 代替 $("#get").animate({opacity: '1'}, 5000); - stackoverflow.com/questions/23180504/…
猜你喜欢
  • 2012-03-03
  • 1970-01-01
  • 1970-01-01
  • 2017-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多