【问题标题】:How to animate text(), html() jquery [closed]如何为文本(),html()jquery设置动画[关闭]
【发布时间】:2013-12-08 09:55:39
【问题描述】:

您好,我制作了更改单词的脚本,但我想在文本更改时添加动画。我该怎么做?

Link here

【问题讨论】:

  • 不是已经有动画了吗?你到底想让它做什么?

标签: jquery animation text jquery-animate


【解决方案1】:

你启动一个动画,启动后直接停止它:

$(".dynamo").animate({"opacity": "0"}, 500).stop();

使用

$(".dynamo")
    .stop() // Stop on-going animation
    .animate({"opacity": "0"}, 500, function() {
        // After first animation finished
        $(this).html(array[i]).animate({ opacity: 1 });
    });

http://jsbin.com/umUWAGu/2

【讨论】:

  • animate中的这个函数是回调函数吗?我是初学者。
  • 确实是回调函数
  • 那么当动画结束并且不透明度为0时函数启动?
  • 是的,根据api(api.jquery.com/animate):complete -- Type: Function() -- A function to call once the animation is complete.
  • 谢谢 :) 你有什么想法可以改进我的 jquery 吗?
【解决方案2】:

您可以使用jquery 库的fadeIn 和fadeOut 方法。 您应该使用 position: absolute 创建第二个元素,将不透明度设置为零并对两个元素进行动画处理(当然,删除第一个元素)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-29
    • 2016-11-13
    • 2019-01-11
    相关资源
    最近更新 更多