【问题标题】:JQuery - Fade out text before chaning the texts textJQuery - 在更改文本文本之前淡出文本
【发布时间】:2017-10-09 08:15:45
【问题描述】:

我有一张覆盖整个屏幕的图片。每隔 5 秒,背景图像就会转换为另一个背景图像。为此,我有一个带有一些漂亮文字的标题。当图片发生变化时,我想淡出我的文本,然后用另一个文本淡入。我已经成功了一半。它改变了文本和淡入淡出。但是,它以一种奇怪的顺序进行。这是我的代码进行更改:

$("header h1").fadeOut(500);
$("#bildfram").css("background-image", "url(" + bilder[bild] + ")" );
$("header h1").text("GeForce | " + text[bild]);
$("header h1").fadeIn(500);

那是代码的顺序。但是执行有点奇怪。在网站上执行是这样的:

Change background image ($("#bildfram").css("background-image", "url(" + bilder[bild] + ")" );)
Change the text ($("header h1").text("GeForce | " + text[bild]);)
Fade out the text ($("header h1").fadeOut(500);)
Fade in the text ($("header h1").fadeIn(500);)

我希望代码按照编写脚本的顺序执行,淡出文本、更改图片、更改文本、淡入文本。

提前致谢!

【问题讨论】:

    标签: javascript jquery html css


    【解决方案1】:

    要在$.fadeOut() 完成后更改某些内容,您需要将更改放入$.fadeOut() 的回调中。

    $("header h1").fadeOut(500, function() {
      $("#bildfram").css("background-image", "url(" + bilder[bild] + ")" );
      $("header h1").text("GeForce | " + text[bild]);
      $("header h1").fadeIn(500);
    });
    

    【讨论】:

    • 感谢您的帮助! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-08
    • 1970-01-01
    • 1970-01-01
    • 2021-07-04
    • 2016-05-31
    • 2023-04-10
    • 1970-01-01
    相关资源
    最近更新 更多